Skip to content

Instantly share code, notes, and snippets.

@GiveMeSomething
Created March 12, 2023 15:13
Show Gist options
  • Save GiveMeSomething/d300bd40be38da6808b6c73a2a9efe0d to your computer and use it in GitHub Desktop.
Save GiveMeSomething/d300bd40be38da6808b6c73a2a9efe0d to your computer and use it in GitHub Desktop.
Protobuf file sharing endpoint
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/_proto/", async ctx =>
{
ctx.Response.ContentType = "text/plain";
using var fs = new FileStream(Path.Combine(env.ContentRootPath, "Proto", "your.proto"), FileMode.Open, FileAccess.Read);
using var sr = new StreamReader(fs);
while (!sr.EndOfStream)
{
var line = await sr.ReadLineAsync();
if (line != "/* >>" || line != "<< */")
{
await ctx.Response.WriteAsync(line);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment