Add CORS headers

This commit is contained in:
Norbi Peti 2021-05-24 17:11:18 +02:00
parent b2eea0abb9
commit f909fce1b7
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 6 additions and 0 deletions

View file

@ -24,4 +24,7 @@
</Reference>
</ItemGroup>
<Target Name="CopyToPlugins" AfterTargets="AfterBuild">
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(OutputPath)\TBConsole.dll" DestinationFolder="$(MSBuildProjectDirectory)\..\..\ref\Plugins" />
</Target>
</Project>

View file

@ -34,6 +34,9 @@ namespace TBConsole
{
var context = await _listener.GetContextAsync();
string resp = await _receiver(await new StreamReader(context.Request.InputStream).ReadToEndAsync());
string origin = context.Request.Headers["Origin"];
if (origin == "http://localhost:4200" || origin == "https://tbconsole.web.app")
context.Response.AddHeader("Access-Control-Allow-Origin", origin);
var sw = new StreamWriter(context.Response.OutputStream);
await sw.WriteLineAsync(resp);
sw.Close();