Browse Source

Add CORS headers

tags/v1.0.0
NorbiPeti 3 years ago
parent
commit
f909fce1b7
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
2 changed files with 6 additions and 0 deletions
  1. +3
    -0
      TBConsole/TBConsole.csproj
  2. +3
    -0
      TBConsole/WebServer.cs

+ 3
- 0
TBConsole/TBConsole.csproj 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>

+ 3
- 0
TBConsole/WebServer.cs 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();


Loading…
Cancel
Save