From e46ce71a22ff8fb9724d800b0c9f959bdfe8a470 Mon Sep 17 00:00:00 2001 From: Jonny Ngo Luong <jonnynl@stud.ntnu.no> Date: Mon, 15 Feb 2021 16:06:28 +0100 Subject: [PATCH] Issue: Split up index and app for testing with Jest (#5) --- server/src/app.ts | 19 +++++++++++++++++++ server/src/index.ts | 17 +---------------- 2 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 server/src/app.ts diff --git a/server/src/app.ts b/server/src/app.ts new file mode 100644 index 0000000..366a655 --- /dev/null +++ b/server/src/app.ts @@ -0,0 +1,19 @@ +import express, { Application } from 'express'; +import routes from "./routes/routes"; +import bodyParser from 'body-parser'; +import cors from 'cors'; +import mysql from 'mysql2'; +// Boot express +const app: Application = express(); + +app.use(cors()); +// Configuring body parser middleware +app.use(bodyParser.urlencoded({ extended: false })); +app.use(bodyParser.json()); + +// Configuring json response +app.set("json spaces", 2); + +app.use("/api", routes); + +export default app; \ No newline at end of file diff --git a/server/src/index.ts b/server/src/index.ts index d4ba8b0..d4b4977 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,23 +1,8 @@ -import bodyParser from 'body-parser'; -import cors from 'cors'; -import express from 'express'; -import routes from './routes/routes'; -import mysql from 'mysql2'; +import app from './app'; // REST API config -const app = express(); const port = 3000; -app.use(cors()); -// Configuring body parser middleware -app.use(bodyParser.urlencoded({ extended: false })); -app.use(bodyParser.json()); - -// Configuring json response -app.set("json spaces", 2); - -app.use("/api", routes); - app.listen(port, () => { console.log(`Listening on port ${port}!`) }); \ No newline at end of file -- GitLab