[backend][nodejs] Use express framework instead of http module
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
"main": "lib/app.js",
|
"main": "lib/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "ts-mocha -p tsconfig.json src/**/*.spec.ts",
|
"test": "ts-mocha -p tsconfig.json src/**/*.spec.ts",
|
||||||
"start": "tsc && node lib/app.js build:live",
|
"start": "tsc && node lib/app.js",
|
||||||
"build": "tsc -p .",
|
"build": "tsc -p .",
|
||||||
"build:live": "nodemon --watch 'src/**/*.ts' --exec \"ts-node\" src/app.ts"
|
"build:live": "nodemon --watch 'src/**/*.ts' --exec \"ts-node\" src/app.ts"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import {IncomingMessage, ServerResponse} from "http";
|
import express from 'express';
|
||||||
|
|
||||||
const http = require('http');
|
|
||||||
const randomDecision = require("./random-decision")
|
const randomDecision = require("./random-decision")
|
||||||
|
|
||||||
|
const app = express();
|
||||||
const port = 3000;
|
const port = 3000;
|
||||||
|
|
||||||
const server = http.createServer((request: IncomingMessage, response: ServerResponse) => {
|
app.get('/', ((req, response) => {
|
||||||
response.statusCode = 200;
|
response.send(randomDecision.getRandomChoice());
|
||||||
response.setHeader('Content-Type', 'text/plain');
|
}));
|
||||||
response.end(randomDecision.getRandomChoice().toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
server.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Server listening on port ${port}`)
|
return console.log(`Server is listening on port ${port}`);
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user