-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
63 lines (48 loc) · 1.39 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
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
require('dotenv').config();
const path = require('path');
const morgan = require('morgan');
const express = require('express');
const mongoose = require('mongoose');
const userRouter = require('./routers/userRouter');
const passwordRouter = require('./routers/passwordRouter');
const viewsRouter =require('./routers/viewsRouter');
const app = express();
// allow express accept json format data
app.use(express.json());
// serve files in 'public' folder without routing
app.use(express.static('./public'));
// HTTP request logger
app.use(morgan('dev'));
// Templates configurations
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// FIXME: TESTING ROUTER
// const testRouter = require('./routers/testRouter');
// app.use('/test', testRouter);
// ROUTERS
app.use('/passwords', passwordRouter);
app.use('/users', userRouter);
//Views
app.use('/' ,viewsRouter);
// DB connection URI
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD,
);
// Connect to DB with mongoose ODM
mongoose
.connect(DB, {
useNewUrlParser: true,
})
.then((con) => {
console.log('DB connecting successful...');
})
.catch((err) => {
console.log('DB connection ERROR!!');
});
// SERVER CONNECTION
app.listen(3000, () => {
console.log('listening on port 3000');
});
// Allow Vercel to turn Express into a serverless function
module.exports = app;