2023-08-16 14:37:39 +00:00
|
|
|
import handy_httpd;
|
|
|
|
import slf4d;
|
|
|
|
import slf4d.default_provider;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
auto provider = new shared DefaultProvider(true, Levels.INFO);
|
|
|
|
configureLoggingProvider(provider);
|
|
|
|
|
|
|
|
HttpServer server = initServer();
|
|
|
|
server.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private HttpServer initServer() {
|
|
|
|
import handy_httpd.handlers.path_delegating_handler;
|
|
|
|
import handy_httpd.handlers.filtered_handler;
|
|
|
|
import auth;
|
2023-08-17 15:55:05 +00:00
|
|
|
import lists;
|
2023-08-16 14:37:39 +00:00
|
|
|
|
|
|
|
ServerConfig config = ServerConfig.defaultValues();
|
|
|
|
config.enableWebSockets = false;
|
|
|
|
config.workerPoolSize = 3;
|
|
|
|
config.port = 8080;
|
|
|
|
config.connectionQueueSize = 10;
|
|
|
|
config.defaultHeaders["Access-Control-Allow-Origin"] = "*";
|
2023-08-17 15:55:05 +00:00
|
|
|
config.defaultHeaders["Access-Control-Allow-Credentials"] = "true";
|
|
|
|
config.defaultHeaders["Vary"] = "origin";
|
|
|
|
config.defaultHeaders["Access-Control-Allow-Headers"] = "Authorization";
|
2023-08-16 14:37:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
auto mainHandler = new PathDelegatingHandler();
|
|
|
|
mainHandler.addMapping(Method.GET, "/status", (ref HttpRequestContext ctx) {
|
|
|
|
ctx.response.writeBodyString("online");
|
|
|
|
});
|
2023-08-17 15:55:05 +00:00
|
|
|
|
|
|
|
auto optionsHandler = toHandler((ref HttpRequestContext ctx) {
|
|
|
|
ctx.response.setStatus(HttpStatus.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
mainHandler.addMapping(Method.POST, "/register", &createNewUser);
|
2023-08-16 14:37:39 +00:00
|
|
|
mainHandler.addMapping(Method.POST, "/login", &handleLogin);
|
2023-08-17 15:55:05 +00:00
|
|
|
mainHandler.addMapping(Method.GET, "/me", &getMyUser);
|
|
|
|
mainHandler.addMapping(Method.OPTIONS, "/**", optionsHandler);
|
|
|
|
mainHandler.addMapping(Method.DELETE, "/me", &deleteMyUser);
|
2023-08-16 14:37:39 +00:00
|
|
|
|
2023-08-17 15:55:05 +00:00
|
|
|
mainHandler.addMapping(Method.GET, "/lists", &getNoteLists);
|
|
|
|
mainHandler.addMapping(Method.POST, "/lists", &createNoteList);
|
|
|
|
mainHandler.addMapping(Method.DELETE, "/lists/{id}", &deleteNoteList);
|
2023-08-16 14:37:39 +00:00
|
|
|
|
|
|
|
return new HttpServer(mainHandler, config);
|
|
|
|
}
|