Skip to content

Commit

Permalink
Add CORS support - fixes #501
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed May 7, 2017
1 parent b19f3ae commit 9a28e5f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ shared static this()
auto urlRouter = new URLRouter;
auto fsettings = new HTTPFileServerSettings;
fsettings.serverPathPrefix = "/static";

void sendOptions(HTTPServerRequest req, HTTPServerResponse res)
{
import std.algorithm.comparison : among;
if (req.host.among("tour.dlang.org", "tour.dlangg.io", "dlang.org", "dtest.dlang.io", "127.0.0.1", "localhost"))
res.headers["Access-Control-Allow-Origin"] = "*";
}
urlRouter
.any("/api/*", &sendOptions)
.registerWebInterface(new WebInterface(contentProvider, config.googleAnalyticsId, defaultLang))
.registerRestInterface(new ApiV1(execProvider, contentProvider))
.get("/static/*", serveStaticFiles(publicDir.buildPath("static"), fsettings));
Expand Down

0 comments on commit 9a28e5f

Please sign in to comment.