-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (50 loc) · 1.33 KB
/
server.js
File metadata and controls
50 lines (50 loc) · 1.33 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
const express = require('express');
const hbs = require('hbs');
const fs = require('fs');
const port = process.env.PORT || 3000;
hbs.registerPartials(__dirname + '/views/partials');
var app=express();
//This is used for the logging the commands to the log file.
app.use((req,res,next)=>{
var date = new Date().toString();
var log = `${date}: ${req.method} ${req.url}`;
console.log(log);
fs.appendFileSync('log.txt',log);
next();
});
//This is used for maintainance.
/*app.use((req,res,next)=>{
res.render('maintainance.hbs',{
pageTitle:"Ouch! Men at work!"
});
next();
});*/
//This is used to link the help page as static webpage.s
app.use(express.static(__dirname + '/public'));
//This is used to add the home page.
app.get('/',(req,res)=>{
res.render('help.hbs',{
pageTitle:'Home Page',
pageContent:'Welcome to my website.',
year:new Date().getFullYear()
});
});
app.get('/about',(req,res)=>{
res.render('about.hbs',{
pageTitle:'About Page',
year:new Date().getFullYear()
});
});
app.get('/bad',(req,res)=>{
res.send({
errorMessage : "Meow! Couldnt handle request!"
});
});
app.get('/projects',(req,res)=>{
res.render('project.hbs',{
pageTitle:'Projects'
});
});
app.listen(port,()=>{
console.log(`Server started on port ${port}`);
});