Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 36f3133

Browse files
fixing CORS for local development
1 parent 4d486d2 commit 36f3133

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/SqlStreamStore.HAL.DevServer/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using KestrelPureOwin;
88
using Microsoft.AspNetCore.Server.Kestrel.Core;
9+
using Microsoft.Owin;
910
using SqlStreamStore.Streams;
1011
using MidFunc = System.Func<
1112
System.Func<
@@ -57,6 +58,7 @@ await server.Start(new UriBuilder
5758
private static Action<BuildFunc> Configure(IStreamStore streamStore)
5859
=> builder => builder
5960
.Use(DisplayErrors)
61+
.Use(AllowAllOrigins)
6062
.Use(SqlStreamStoreHalMiddleware.UseSqlStreamStoreHal(streamStore));
6163

6264
private static MidFunc DisplayErrors => next => async env =>
@@ -71,6 +73,20 @@ private static Action<BuildFunc> Configure(IStreamStore streamStore)
7173
}
7274
};
7375

76+
// don't actually do this in production
77+
private static MidFunc AllowAllOrigins => next => env =>
78+
{
79+
var context = new OwinContext(env);
80+
81+
context.Response.OnSendingHeaders(_ =>
82+
{
83+
var response = (IOwinResponse) _;
84+
response.Headers["Access-Control-Allow-Origin"] = "*";
85+
}, context.Response);
86+
87+
return next(env);
88+
};
89+
7490
private static void DisplayMenu(IStreamStore streamStore)
7591
{
7692
while(true)

0 commit comments

Comments
 (0)