Created
March 24, 2018 15:38
-
-
Save florentinH/95d7442824ba181616f5f94aefe9c3a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let http = require('http') | |
let port = 3000 | |
const Handlebars = require('handlebars') | |
const express = require('express') | |
const app = express() | |
const home = ` | |
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<title>{{pageTitle}}</title> | |
</head> | |
<body> | |
<h1>{{title}}</h1> | |
<p>{{paragraph}}</p> | |
<ul> | |
{{#each items}} | |
<li><a href="{{pageUrl}}">{{name}}</a></li> | |
{{/each}} | |
</ul> | |
</body> | |
</html> | |
` | |
const about = ` | |
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<title>{{pageTitle}}</title> | |
</head> | |
<body> | |
<h1>A propos</h1> | |
<p>Toi aussi demande à Dora de chanter avec toi !</p> | |
<ul> | |
{{#each items}} | |
<li><a href="{{pageUrl}}">{{name}}</a></li> | |
{{/each}} | |
</ul> | |
</body> | |
</html> | |
` | |
const templateHome = Handlebars.compile(home) | |
const templateAbout = Handlebars.compile(about) | |
app.get('/', (req, res) => { | |
res.end(templateHome({ | |
pageTitle: 'challenge node HTTP Florentin', | |
title: 'Bonjour petit JS', | |
paragraph: 'Bienvenu sur mon challenge !', | |
items: [ | |
{ name: 'A propos', pageUrl: '/about' }, | |
] | |
})) | |
}) | |
app.get('/about', (req, res) => { | |
res.end(templateAbout({ | |
items: [ | |
{ name: 'Au revoir Dora', pageUrl:'/' }, | |
] | |
})) | |
}) | |
app.listen(port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment