aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.ts12
-rw-r--r--src/index.ts7
2 files changed, 14 insertions, 5 deletions
diff --git a/src/app.ts b/src/app.ts
index fe00367..345b73f 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -1,13 +1,23 @@
-import * as express from 'express'
+import * as express from 'express';
+import * as logger from 'morgan';
+import * as bodyParser from 'body-parser';
class App {
public express
constructor () {
this.express = express()
+ this.middleware()
this.mountRoutes()
}
+ // Configure Express middleware.
+ private middleware(): void {
+ this.express.use(logger('combined'));
+ this.express.use(bodyParser.json());
+ this.express.use(bodyParser.urlencoded({ extended: false }));
+ }
+
private mountRoutes (): void {
const router = express.Router()
router.get('/', (req, res) => {
diff --git a/src/index.ts b/src/index.ts
index 80a02d9..69150e2 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,9 +1,8 @@
-console.log('Hello, TypeScript!');
-
-
+console.log('Welcome to the CS3099 Server thingy!');
import app from './app'
+// use default port 3000 or port supplied by OS
const port = process.env.PORT || 3000
app.listen(port, (err) => {
@@ -11,5 +10,5 @@ app.listen(port, (err) => {
return console.log(err)
}
- return console.log(`server is listening on ${port}`)
+ return console.log(`server is listening on port ${port}`)
}) \ No newline at end of file