-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.js
52 lines (49 loc) · 2.22 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
/*******************************************************************************
* Feel free to remove this comment block and all other comments after pulling.
* They're for information purposes only.
*
* This layout is provided to you for an easy and quick setup to either pull
* or use to correct yours after working at least 1 hour on Team Activity 02.
* Throughout the course, we'll be using Express.js for our view engines.
* However, feel free to use pug or handlebars ('with extension hbs'). You will
* need to make sure you install them beforehand according to the reading from
* Udemy course.
* IMPORTANT: Make sure to run "npm install" in your root before "npm start"
*******************************************************************************/
// Our initial setup (package requires, port number setup)
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const PORT = process.env.PORT || 5005; // So we can run on heroku || (OR) localhost:5000
const app = express();
// Route setup. You can implement more in the future!
const ta01Routes = require('./routes/ta01');
const ta02Routes = require('./routes/ta02');
const ta03Routes = require('./routes/ta03');
const ta04Routes = require('./routes/ta04');
app
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
// For view engine as Pug
//.set('view engine', 'pug') // For view engine as PUG.
// For view engine as hbs (Handlebars)
//.engine('hbs', expressHbs({layoutsDir: 'views/layouts/', defaultLayout: 'main-layout', extname: 'hbs'})) // For handlebars
//.set('view engine', 'hbs')
.use(bodyParser({ extended: false })) // For parsing the body of a POST
.use('/ta01', ta01Routes)
.use('/ta02', ta02Routes)
.use('/ta03', ta03Routes)
.use('/ta04', ta04Routes)
.get('/', (req, res, next) => {
// This is the primary index, always handled last.
res.render('pages/index', {
title: 'Welcome to my CSE341 repo',
path: '/',
});
})
.use((req, res, next) => {
// 404 page
res.render('pages/404', { title: '404 - Page Not Found', path: req.url });
})
.listen(PORT, () => console.log(`Listening on ${PORT}`));