HJW

Initial commit.

1 +node_modules
...\ No newline at end of file ...\ No newline at end of file
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
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
1 +{
2 + "name": "meadowlark",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "meadowlark.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC"
11 +}
1 +<h1>404 - Not Found</h1>
1 +<h1>500 - Server Error</h1>
...\ No newline at end of file ...\ No newline at end of file
1 +<h1>About Meadowlark Travel</h1>
2 +<p>
3 +Your fortune for the day:
4 +</p>
5 +<blockquote>{{fortune}}</blockquote>
...\ No newline at end of file ...\ No newline at end of file
1 +<h1>Welcome to Meadowlark Travel</h1>
...\ No newline at end of file ...\ No newline at end of file
1 +<!doctype html>
2 +<html>
3 + <head>
4 + <title>Meadowlark Travel</title>
5 +</head>
6 +<body>
7 + <header><img src = "/img/logo2.png" alt="Meadowlark Travel Logo"></header>
8 + {{{body}}}
9 +</body>
10 +</html>
...\ No newline at end of file ...\ No newline at end of file