mancala/src/server/ExpressApp.ts

28 lines
847 B
TypeScript
Raw Normal View History

2022-07-15 21:42:51 +03:00
import cors from "cors";
import express from "express";
import { Request, Response } from "express";
import morgan from "morgan";
import fs from "fs";
import { generateKey } from "../util/key_factory";
export class ExpressApp {
private createAccessLogMiddleware() {
return morgan("common", {
stream: fs.createWriteStream("./access.log", { flags: "a" }),
});
}
public createExpressApp(): Express.Application {
const app = express();
app.use(cors());
app.use(this.createAccessLogMiddleware());
app.use(morgan("dev"));
app.get("/", (req: Request, res: Response) => {
res.send("Server up and running!");
});
app.get("/register/", (req: Request, res: Response) => {
res.send(generateKey());
});
return app;
}
}