Skip to content

Instantly share code, notes, and snippets.

@anthonyquizon
Created June 9, 2020 01:21
Show Gist options
  • Save anthonyquizon/9883676fb9e9503ee259d3e731e97da0 to your computer and use it in GitHub Desktop.
Save anthonyquizon/9883676fb9e9503ee259d3e731e97da0 to your computer and use it in GitHub Desktop.
Dlang Vibe.d REST with CORS example
const PORT = 8008;
interface APIInterface {
@safe:
string postMatches();
string get();
}
class APIHandlers : APIInterface {
@safe:
override:
string postMatches() {
return "hello";
}
string get() {
return "hello";
}
}
//TODO .env
void main() {
auto settings = new HTTPServerSettings;
auto router = new URLRouter;
auto restSettings = new RestInterfaceSettings;
restSettings.allowedOrigins = ["*"];
router.registerRestInterface(new APIHandlers, restSettings);
settings.port = PORT;
settings.bindAddresses = ["::1", "0.0.0.0"];
listenHTTP(settings, router);
runApplication();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment