-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (41 loc) · 1.18 KB
/
index.js
File metadata and controls
60 lines (41 loc) · 1.18 KB
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
import express from 'express';
import csrf from 'csurf';
import cookieParser from 'cookie-parser';
import dotenv from 'dotenv';
import userRoutes from './routes/userRoutes.js';
import propertiesRoutes from './routes/propertiesRoutes.js';
import appRoutes from './routes/appRoutes.js';
import apiRoutes from './routes/apiRoutes.js';
import db from './config/db.js';
dotenv.config({ path: '.env' });
//Create app
const app = express();
//Enable form data reading
app.use(express.urlencoded({extended: true}));
//Enable Cookie Parser
app.use( cookieParser());
//Enable CSRF
app.use(csrf({cookie: true}));
//Connection to the database
try{
await db.authenticate();
//Create tables if it doesn't exist
db.sync();
console.log('Successfully connected to the database')
} catch (e){
console.log(e);
}
//Enable Pug
app.set('view engine','pug');
app.set('views','./views');
//Public folder
app.use(express.static('public'));
//Routing
app.use('/',appRoutes);
app.use('/auth',userRoutes);
app.use('/',propertiesRoutes);
app.use('/api',apiRoutes);
const port = process.env.BACKEND_PORT || 3000;
app.listen(port, () =>{
console.log(`The server is running on port ${port}`)
});