waffle/src/index.ts

34 lines
781 B
TypeScript
Raw Normal View History

2022-04-05 22:34:06 +03:00
import "dotenv/config";
2022-04-04 16:50:52 +03:00
import express from "express";
2022-04-10 01:22:07 +03:00
import { createServer } from "node:http";
2022-04-05 22:34:06 +03:00
import databaseInit from "./database/init";
2022-04-10 01:22:07 +03:00
import gateway from "./gateway";
2022-04-05 22:34:06 +03:00
import server from "./server";
const port = process.env.PORT || 3000;
2022-04-04 16:50:52 +03:00
const app = express();
2022-04-05 22:34:06 +03:00
server(app);
2022-04-10 01:22:07 +03:00
const httpServer = createServer(app);
gateway(httpServer);
2022-04-05 22:34:06 +03:00
function serve() {
2022-04-10 01:22:07 +03:00
httpServer.listen(port, () => console.log(`listening on port ${port}`));
2022-04-05 22:34:06 +03:00
}
async function main() {
if (process.argv[2] === "db-init") {
console.log("db-init: initializing database...");
await databaseInit();
console.log("db-init: databaseInit() finished");
console.log("database initialized, exiting...");
process.exit(0);
return;
}
2022-04-04 16:50:52 +03:00
2022-04-05 22:34:06 +03:00
serve();
}
2022-04-04 16:50:52 +03:00
2022-04-05 22:34:06 +03:00
main();