Skip to content

Commit 0715fcc

Browse files
author
Michal Zoltowski
committed
Initial commit
0 parents  commit 0715fcc

File tree

9 files changed

+119
-0
lines changed

9 files changed

+119
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
server.log

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "node-web-derver",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"express": "^4.16.4",
13+
"hbs": "^4.0.1"
14+
}
15+
}

public/help.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Help Page</title>
6+
</head>
7+
<body>
8+
<h1>Help Page</h1>
9+
<p>Some text here</p>
10+
</body>
11+
</html>

server.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const express = require('express');
2+
const hbs = require('hbs');
3+
const fs = require('fs');
4+
var app = express();
5+
6+
hbs.registerPartials(__dirname + '/views/partials');
7+
hbs.registerHelper('getCurentYear', ()=>{
8+
return new Date().getFullYear();
9+
});
10+
hbs.registerHelper('screamIt', (text) => {
11+
return text.toUpperCase();
12+
});
13+
14+
15+
app.set('view engine', 'hbs')
16+
.get('/', (req,res) => {
17+
res.render('home', {
18+
pageTitle: 'Home Page',
19+
welcome: 'Witam na mojej stronie'
20+
});
21+
})
22+
.use((req, res, next) => {
23+
var now = new Date().toString();
24+
var log = `${now}: ${req.method} ${req.url}`;
25+
fs.appendFile('server.log', log + '\n', (err)=>{
26+
if(err){
27+
console.log('Unable to save');
28+
}
29+
});
30+
console.log(log);
31+
next();
32+
})
33+
// .use((req, res, next) => {
34+
// res.render('maitens');
35+
// })
36+
.use(express.static(__dirname + '/public'))
37+
.get('/about', (req,res)=>{
38+
res.render('about.hbs', {
39+
pageTitle: 'About Page',
40+
});
41+
})
42+
.get('/bad', (req,res) => {
43+
res.send({
44+
errorMessage: 'Bad Getaway mother fucker'
45+
});
46+
})
47+
.listen(3000,'localhost');

views/about.hbs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>{{ pageTitle }}</title>
6+
</head>
7+
<body>
8+
{{> header }}
9+
<p>Some text here</p>
10+
{{> footer }}
11+
</body>
12+
</html>

views/home.hbs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>{{ pageTitle }}</title>
6+
</head>
7+
<body>
8+
{{> header }}
9+
<p>{{ screamIt welcome }}</p>
10+
11+
{{> footer }}
12+
</body>
13+
</html>

views/maitens.hbs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Some Page</title>
6+
</head>
7+
<body>
8+
<h1> We`ll right back </h1>
9+
<p> The site is currently being updated. </p>
10+
</body>
11+
</html>

views/partials/footer.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<footer>
2+
<p>Created By Michał - Copyright {{ getCurentYear }}</p>
3+
</footer>

views/partials/header.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<header>
2+
<h1>{{ pageTitle }}</h1>
3+
<p><a href = "/">Home</a></p>
4+
<p><a href = "/about">About</a></p>
5+
</header>

0 commit comments

Comments
 (0)