-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
75 lines (63 loc) · 1.94 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const path = require('path');
const session = require('express-session');
//const morgan = require('morgan');
// Imports routes for the products
const product = require('./routes/product.route');
const user = require('./routes/user.route');
const admin = require('./routes/admin.route');
// initialize our express app
const app = express();
//app.use(morgan('combined'))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Methods',
'OPTIONS, GET, POST, PUT, PATCH, DELETE'
);
//res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
});
app.use(
session({
name: 'sid',
resave: false,
saveUninitialized: false,
secret: 'secret',
cookie: {
//this is 15 hours
maxAge: 5.4e7,
sameSite: true,
// secure: true
},
})
);
app.use('/', product);
app.use('/user/', user);
//dashboard
app.use('/area51/admin/', admin);
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }));
app.engine('pug', require('pug').__express);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
const uri =
// 'mongodb://localhost:27017/invsystem';
'mongodb+srv://Fort:fortune@cluster0.144qe.mongodb.net/KhanShoeCenter?retryWrites=true&w=majority';
mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
});
// start the server listening for requests
app.listen(process.env.PORT || 3000, () =>
console.log(`The program is running`)
);
// app.listen(port, () => {
// console.log('Server is up and running on port numner ' + port);
// });