From f909fce1b741127f56a03c848463ba40ec4748a6 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 24 May 2021 17:11:18 +0200 Subject: [PATCH] Add CORS headers --- TBConsole/TBConsole.csproj | 3 +++ TBConsole/WebServer.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/TBConsole/TBConsole.csproj b/TBConsole/TBConsole.csproj index 988c6ae..e809eb3 100644 --- a/TBConsole/TBConsole.csproj +++ b/TBConsole/TBConsole.csproj @@ -24,4 +24,7 @@ + + + diff --git a/TBConsole/WebServer.cs b/TBConsole/WebServer.cs index 811d48d..b813b7d 100644 --- a/TBConsole/WebServer.cs +++ b/TBConsole/WebServer.cs @@ -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();