Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
feat(server): add express server
Browse files Browse the repository at this point in the history
  • Loading branch information
elanum committed Dec 10, 2020
1 parent 4fc295e commit 41ba8d5
Show file tree
Hide file tree
Showing 3 changed files with 1,197 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "workspace-booking-server",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "nodemon server.js"
},
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1"
},
"devDependencies": {
"nodemon": "^2.0.6"
}
}
29 changes: 29 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 5000;

app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use((req, _res, next) => {
console.log(`request of type ${req.method} to URL ${req.originalUrl}`);
url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
next();
});

app.route('/api/hello').get((_req, res) => {
res.status(200).json({
message: 'World',
});
});

app.use((_req, res) => {
res.status(404).json({
message: 'Not found',
});
});

app.listen(port, () => console.log(`app listening on port ${port}!`));
Loading

0 comments on commit 41ba8d5

Please # to comment.