45 lines
1.2 KiB
D
45 lines
1.2 KiB
D
import handy_httpd;
|
|
import handy_httpd.handlers.path_handler;
|
|
import d2sqlite3;
|
|
import std.process;
|
|
|
|
import db;
|
|
import api_modules.auth;
|
|
static import api_modules.classroom_compliance;
|
|
|
|
void main() {
|
|
string env = environment.get("TEACHER_TOOLS_API_ENV", "DEV");
|
|
|
|
// Initialize the database on startup.
|
|
auto db = getDb();
|
|
db.close();
|
|
|
|
ServerConfig config;
|
|
config.enableWebSockets = false;
|
|
config.port = 8080;
|
|
config.workerPoolSize = 3;
|
|
|
|
config.defaultHeaders["Access-Control-Allow-Origin"] = "*";
|
|
config.defaultHeaders["Access-Control-Allow-Methods"] = "*";
|
|
config.defaultHeaders["Access-Control-Request-Method"] = "*";
|
|
config.defaultHeaders["Access-Control-Allow-Headers"] = "Authorization, Content-Length, Content-Type";
|
|
|
|
if (env == "PROD") {
|
|
config.port = 8107;
|
|
config.workerPoolSize = 5;
|
|
}
|
|
|
|
|
|
PathHandler handler = new PathHandler();
|
|
handler.addMapping(Method.OPTIONS, "/api/**", &optionsEndpoint);
|
|
handler.addMapping(Method.POST, "/api/auth/login", &loginEndpoint);
|
|
api_modules.classroom_compliance.registerApiEndpoints(handler);
|
|
|
|
HttpServer server = new HttpServer(handler, config);
|
|
server.start();
|
|
}
|
|
|
|
void optionsEndpoint(ref HttpRequestContext ctx) {
|
|
ctx.response.status = HttpStatus.OK;
|
|
}
|