-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
72 lines (54 loc) · 1.59 KB
/
app.js
File metadata and controls
72 lines (54 loc) · 1.59 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
61
62
63
64
65
66
67
68
69
70
71
72
const path = require("path"); // core node module
const express = require("express"); // npm module
const app = express();
const port = process.env.PORT || 3000;
const hbs = require('hbs');
// const bodyParser = require("body-parser");
// const ejs = require("ejs");
// custom directory for views folder...
// const viewsPath = path.join(__dirname, '../templates');
// app.set('views', viewsPath);
app.set('view engine', 'hbs');
app.use(express.static("public"));
//const partials = path.join(__dirname, '../views/partials');
hbs.registerPartials('./views/partials/');
// console.log(__dirname);
// console.log(__filename);
app.get('', (req, res) => {
res.render('index',
{title: 'Chatter Bug App',
name: 'Alexandre Mokbel'});
});
app.get('/about', (req, res) => {
res.render('about', {
name: 'Alexandre Mokbel'
});
})
app.get("/help", (req, res) => {
//res.send({ name: "Alex", age: 35 });
res.render('help');
});
app.get('/products', (req, res) => {
if(!req.query.search) {
return res.send({error:
'You must provide a search term'});
}
console.log(req.query);
res.send( {
products: []
});
});
app.get('/help/*', (req,res) => {
res.render('404', { myPartial : '404help', name: 'Alexandre Mokbel' });
});
// This is a wildcard character, it should come last as anything will match it
app.get('*', (req, res) => {
res.render('404', { myPartial: "404generic", name: "Alexandre Mokbel"});
// res.send('My 404 page');
})
app.get("/residents", (req, res) => {
res.send("RESIDENTS PAGE");
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});