-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (29 loc) · 1 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* eslint-disable no-console */
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const path = require('path');
// const cors = require('cors');
const logger = require('morgan');
const knexLogger = require('knex-logger');
const db = require('./db/knex1');
// setting the path of the router file to variable so that we can use all the routes from it.
const router = require('./routes/router.js');
// body parser Middleware
app.use(bodyParser.json());
// logging
app.use(logger('dev'));
app.use(knexLogger(db));
// app.use(cors({origin: 'http://localhost:3000'}));
// this will set/use our api to initial path of /api.
app.use('/api', router);
// use 5000 port no. for server.
const port = process.env.PORT || 5000;
// build to serve static files.
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/*', (req, res) => {
res.sendFile('index.html', { root: './client/build' });
});
app.listen(port, () => {
console.log('Server Started');
});