EJS test

Javascript code posted
created at 25 Apr 05:03, updated at 30 May 19:25

Edit | Back
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
const express = require('express');sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
const morgan = require('morgan');
const session = require('express-session');
const flash = require('connect-flash');

require('dotenv').config();
require('./libs/dbConnect');

const { verifyUser } = require('./libs/middleware');
const userRouter = require('./routes/user.route');
const dashboardRouter = require('./routes/dashboard.route');

const app = express();

app.set('views', './views');
app.set('view engine', 'ejs');

app.use(morgan('dev'));
app.use(express.static('./public'));
app.use(express.urlencoded({ extended: false }));

app.use(
  session({
    secret: process.env.AUTH_SECRET,
    saveUninitialized: true,
    resave: false,
  })
);

app.use(flash());

app.use('/', userRouter);
app.use('/dashboard', verifyUser, dashboardRouter);

app.get('*', (req, res) => {
  res.status(404).render('index', { 
    title:'Not Found',
    message: 'Not Found' 
  });
});

const PORT = 3000;

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});
1.22 KB in 3 ms with coderay