Created
June 9, 2020 01:21
-
-
Save anthonyquizon/9883676fb9e9503ee259d3e731e97da0 to your computer and use it in GitHub Desktop.
Dlang Vibe.d REST with CORS example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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