import * as cors from "cors"; import * as express from "express"; import * as morgan from "morgan"; import { createHandler } from "graphql-http/lib/use/express"; import { apiRouter, webRouter } from "./routers"; import { swaggerUIServe, swaggerUISetup } from "../../libs/swagger"; import { schema, root } from "../../libs/graphql"; const helmet = require("helmet"); export default class ExpressApp { private static _instance: express.Express; // eslint-disable-next-line @typescript-eslint/no-empty-function private constructor() {} private static initRouters() { this._instance.use("/api", apiRouter); this._instance.use("/", webRouter); this._instance.use("/swagger", swaggerUIServe, swaggerUISetup); this._instance.use("/graphql", createHandler({ schema: schema, rootValue: root })); } public static get instance(): express.Express { if (!this._instance) { this._instance = express(); this._instance.use(cors()); this._instance.use(morgan("combined")); this._instance.use(express.urlencoded({ extended: true })); this._instance.use(express.json()); // this._instance.use(helmet.contentSecurityPolicy()); // this._instance.use(helmet.crossOriginEmbedderPolicy()); this._instance.use(helmet.crossOriginOpenerPolicy()); this._instance.use(helmet.crossOriginResourcePolicy()); this._instance.use(helmet.dnsPrefetchControl()); this._instance.use(helmet.expectCt()); this._instance.use(helmet.frameguard()); this._instance.use(helmet.hidePoweredBy()); this._instance.use(helmet.hsts()); this._instance.use(helmet.ieNoOpen()); this._instance.use(helmet.noSniff()); this._instance.use(helmet.originAgentCluster()); this._instance.use(helmet.permittedCrossDomainPolicies()); this._instance.use(helmet.referrerPolicy()); this._instance.use(helmet.xssFilter()); this.initRouters(); } return this._instance; } }