-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (22 loc) · 966 Bytes
/
Copy pathapp.js
File metadata and controls
30 lines (22 loc) · 966 Bytes
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
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const adminData = require('./routes/admin');
const shopRoutes = require('./routes/shop');
const rootDir = require('./util/path');
const app = express();
// no need to register the engin, as exoress auto register it
app.set('view engine', 'ejs');
app.set('views', 'views');
app.use(bodyParser.urlencoded({extended : true}));
app.use(express.static(path.join(rootDir, 'public')));
app.use('/admin',adminData.routes);
app.use(shopRoutes);
app.use((req, res, next) => {
res.status(404);
res.setHeader('Content-type','text/html');
// passing the argument to templating engine doesnt change, it remains the same
// "path: 'Error'" we passed becasue ejs engin will check "path" argument in naviagation bar logic of template. if we will not provide, we will get an error
res.render('404', {pageTitle: "404", path: 'Error'});
});
app.listen(3000);