38 lines
1.3 KiB
D
38 lines
1.3 KiB
D
|
import handy_httpd;
|
||
|
import handy_httpd.handlers.path_delegating_handler;
|
||
|
import handy_httpd.handlers.file_resolving_handler;
|
||
|
import slf4d;
|
||
|
import slf4d.default_provider;
|
||
|
|
||
|
void main() {
|
||
|
auto provider = new shared DefaultProvider(true, Levels.INFO);
|
||
|
configureLoggingProvider(provider);
|
||
|
|
||
|
ServerConfig config = ServerConfig.defaultValues();
|
||
|
config.workerPoolSize = 3;
|
||
|
config.connectionQueueSize = 10;
|
||
|
config.port = 8100;
|
||
|
|
||
|
PathDelegatingHandler handler = new PathDelegatingHandler();
|
||
|
handler.addMapping("POST", "/extracts", &handleExtract);
|
||
|
handler.addMapping("GET", "/extracts/{extractId:uint}", &getExtract);
|
||
|
|
||
|
FileResolvingHandler fileHandler = new FileResolvingHandler("site", DirectoryResolutionStrategies.serveIndexFiles);
|
||
|
handler.addMapping("/**", fileHandler);
|
||
|
new HttpServer(handler, config).start();
|
||
|
}
|
||
|
|
||
|
void handleExtract(ref HttpRequestContext ctx) {
|
||
|
MultipartFormData data = ctx.request.readBodyAsMultipartFormData();
|
||
|
infoF!"Read %d files: "(data.elements.length);
|
||
|
|
||
|
import std.json;
|
||
|
JSONValue result = JSONValue.emptyObject;
|
||
|
result.object["extractId"] = JSONValue(42);
|
||
|
ctx.response.writeBodyString(result.toJSON(), "application/json");
|
||
|
}
|
||
|
|
||
|
void getExtract(ref HttpRequestContext ctx) {
|
||
|
infoF!"Getting extract: %d"(ctx.request.getPathParamAs!uint("extractId"));
|
||
|
}
|