-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (32 loc) · 1.19 KB
/
index.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
const express = require('express');
const app = express();
const connectDB = require('./config/db');
const path = require('path');
const PORT = require("config").get('PORT');
const morgan = require('morgan');
///connecting to MONGODB
connectDB();
app.use(function (req, res, next) {
console.log('%s %s', req.method, req.url);
next();
});
/// initializing middleware
app.use(express.urlencoded({ extended: false }));
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'))
app.use(express.json());
app.use('/uploads', express.static('uploads'));
app.use('/confirmation', require('./api/confirmation'));
app.use('/api/auth', require('./api/auth'));
app.use('/api/locality', require('./api/locality'));
app.use('/api/user', require('./api/user'));
app.use('/api/post', require('./api/post'));
app.use('/api/animals', require('./api/animals'));
app.use('/api/street', require('./api/street'));
if (process.env.NODE_ENV === 'production') {
///set Static Folder
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
app.listen(PORT, () => console.log(`listening on PORT ${PORT}`));