add ExpressApp
This commit is contained in:
parent
1b1b931dfc
commit
bb42643e20
27
src/server/ExpressApp.ts
Normal file
27
src/server/ExpressApp.ts
Normal file
@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user