28 lines
847 B
TypeScript
28 lines
847 B
TypeScript
|
|
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;
|
||
|
|
}
|
||
|
|
}
|