Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const bodyParser = require('body-parser');
- const path = require('path');
- const cors = require('cors');
- const port = process.env.port || 3000;
- const { database } = require('./database');
- const router = require('./router');
- const app = express();
- app.use(cors());
- // static folder
- app.use(express.static(path.join(__dirname, 'dist')));
- // parse requests of content-type - application/x-www-form-urlencoded
- app.use(bodyParser.urlencoded({ extended: false }));
- // parse requests of content-type - application/json
- app.use(bodyParser.json());
- // route to retrieve all employees from the database
- app.use('/employees', router);
- // route to save an employee to the database
- app.use('/employees/register', router);
- // route to update an employee's details
- app.use('/employees/update/id', router);
- // route to delete an employee
- app.use('/employees/delete/employee/id', router);
- // handle all other requests
- app.get('*', (req, res) => {
- res.sendFile(path.join(__dirname, 'dist/index.html'));
- });
- app.listen(port, () => console.log('Server running on port ' + port));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement