Showing
11 changed files
with
91 additions
and
0 deletions
.gitignore.txt
0 → 100644
1 | +node_modules | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
helloWorld.js
0 → 100644
1 | +var http = require('http'); | ||
2 | + | ||
3 | +http.createServer(function (req, res) { | ||
4 | + var path = req.url.replace(/\/?(?:\?.*)?$/, '').toLowerCase(); | ||
5 | + switch (path) { | ||
6 | + case '': | ||
7 | + res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
8 | + res.end('Homepage'); | ||
9 | + break; | ||
10 | + case '/about': | ||
11 | + res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
12 | + res.end('About'); | ||
13 | + default: | ||
14 | + res.writeHead(404, { 'Content-Type': 'text/plain' }); | ||
15 | + res.end('Not Found'); | ||
16 | + break; | ||
17 | + } | ||
18 | +}).listen(3000); | ||
19 | + | ||
20 | +console.log('Server started on localhost:3000; press Ctrl-C to terminate....'); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
meadowlark.js
0 → 100644
1 | +var express = require('express'); | ||
2 | + | ||
3 | +var fortunes = [ | ||
4 | + "Conquer your fears or they will conquer you.", | ||
5 | + "Rivers need springs.", | ||
6 | + "Do not fear what you don't know.", | ||
7 | + "You will have a pleasant surprise.", | ||
8 | + "Whenever possible, keep it simple.", | ||
9 | +]; | ||
10 | + | ||
11 | +var app = express(); | ||
12 | +app.use(express.static(__dirname + '/public')); | ||
13 | + | ||
14 | +var handlebars = require('express-handlebars').create({ defaultLayout: 'main' }); | ||
15 | +app.engine('handlebars', handlebars.engine); | ||
16 | +app.set('view engine', 'handlebars'); | ||
17 | + | ||
18 | +app.set('port', process.env.PORT || 3000); | ||
19 | + | ||
20 | +app.get('/', function (req, res) { | ||
21 | + res.render('home'); | ||
22 | +}); | ||
23 | +app.get('/about', function (req, res) { | ||
24 | + var randomFortune = fortunes[Math.floor(Math.random() * fortunes.length)]; | ||
25 | + res.render('about', { fortune : randomFortune}); | ||
26 | +}); | ||
27 | + | ||
28 | +//404 Page | ||
29 | +app.use(function (req, res, next) { | ||
30 | + res.status(404); | ||
31 | + res.render('404'); | ||
32 | +}); | ||
33 | +app.use(function (err, req, res, next) { | ||
34 | + res.status(500); | ||
35 | + res.render('500'); | ||
36 | +}); | ||
37 | + | ||
38 | +app.listen(app.get('port'), function () { | ||
39 | + console.log('Express started on http://localhost:' + app.get('port') | ||
40 | + + '; press Ctrl-C to terminate.'); | ||
41 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
package.json
0 → 100644
public/img/logo.png
0 → 100644
58.3 KB
public/img/logo2.png
0 → 100644
2.17 KB
views/404.handlebars
0 → 100644
1 | +<h1>404 - Not Found</h1> |
views/500.handlebars
0 → 100644
1 | +<h1>500 - Server Error</h1> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
views/about.handlebars
0 → 100644
views/home.handlebars
0 → 100644
1 | +<h1>Welcome to Meadowlark Travel</h1> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
views/layouts/main.handlebars
0 → 100644
-
Please register or login to post a comment