diff --git a/src/app/application.ts b/src/app/application.ts new file mode 100644 index 0000000..a597d54 --- /dev/null +++ b/src/app/application.ts @@ -0,0 +1,23 @@ +import express, { Application as ExpressApp } from "express" + +class Application { + private readonly _instance: ExpressApp + + get instance(): ExpressApp { + return this._instance + } + + constructor() { + this._instance = express() + this._instance.use(express.json()) + this.registerRoutes() + } + + private registerRoutes(): void { + this._instance.get("/", (req, res) => { + res.send("Hello World!") + }) + } +} + +export default new Application() diff --git a/src/app/routes.ts b/src/app/routes.ts new file mode 100644 index 0000000..9a4b9e1 --- /dev/null +++ b/src/app/routes.ts @@ -0,0 +1,3 @@ +const index = (req: any, res: any) => { + res.send("Hello World!") +} diff --git a/src/server.ts b/src/server.ts index 2850e1b..546c6e0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,13 +1,13 @@ import { createServer } from "http" -import Express from "express" import { SERVER_PORT } from "./app.config" import { info } from "@cubetiq/ts-common/dist/log" +import application from "./app/application" // get current host id const hostId = `${require("os").hostname()}#${process.pid}` const startedAt = new Date() -const app = Express() +const app = application.instance const httpServer = createServer(app) info( @@ -15,7 +15,7 @@ info( ) httpServer.listen(SERVER_PORT) -app.get("/", (req, res) => { +app.get("/info", (req, res) => { res.type("json") res.send({ startedAt,