2021-06-11 17:46:26 +08:00
|
|
|
import * as path from "path";
|
|
|
|
import { HttpServer } from "tsrpc";
|
2021-06-14 17:45:11 +08:00
|
|
|
import { enableCookie } from "./models/enableCookie";
|
|
|
|
import { ServerSession } from "./models/ServerSession";
|
2021-06-11 17:46:26 +08:00
|
|
|
import { serviceProto } from "./shared/protocols/serviceProto";
|
|
|
|
|
|
|
|
// Create the Server
|
|
|
|
const server = new HttpServer(serviceProto, {
|
|
|
|
port: 3000,
|
|
|
|
cors: '*'
|
|
|
|
});
|
|
|
|
|
2021-06-14 17:45:11 +08:00
|
|
|
// Enable Cookie
|
|
|
|
enableCookie(server);
|
|
|
|
|
|
|
|
// Enable Session
|
|
|
|
new ServerSession().enable(server);
|
2021-06-11 17:46:26 +08:00
|
|
|
|
|
|
|
// Entry function
|
|
|
|
async function main() {
|
|
|
|
// Auto implement APIs
|
|
|
|
await server.autoImplementApi(path.resolve(__dirname, 'api'));
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// Prepare something... (e.g. connect the db)
|
|
|
|
|
|
|
|
await server.start();
|
|
|
|
};
|
|
|
|
|
|
|
|
main().catch(e => {
|
|
|
|
// Exit if any error during the startup
|
|
|
|
server.logger.error(e);
|
|
|
|
process.exit(-1);
|
|
|
|
});
|