Skip to content
Permalink
Browse files

06-404

  • Loading branch information...
sevilayha committed Aug 5, 2016
1 parent 0469d48 commit 61af7a31f2aede6813930abd1ba73acedd818a85
Showing with 117 additions and 133 deletions.
  1. +10 −0 404.html
  2. +0 −21 LICENSE
  3. +0 −1 README.md
  4. +0 −7 app/controllers/dashboard.controller.js
  5. +0 −32 app/controllers/site.controller.js
  6. +0 −22 app/middleware/nameCheck.js
  7. +0 −28 app/routes.js
  8. +18 −0 contact.html
  9. +10 −0 index.html
  10. +15 −8 package.json
  11. +64 −14 server.js
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Are you lost?</title>
</head>
<body>
404 not found
</body>
</html>
21 LICENSE

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact Page</title>
</head>
<body>

<form method="POST" action="/contact">
<input type="text" name="name">

<input type="email" name="email">

<button type="submit">Submit</button>
</form>

</body>
</html>
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
I am an HTML Page
</body>
</html>
@@ -1,17 +1,24 @@
{
"name": "node-routing",
"name": "node-routing-course",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"express": "^4.14.0",
"morgan": "~1.7.0",
"body-parser": "~1.15.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/scotch-io/node-routing-course.git"
},
"author": "",
"license": "MIT"
"license": "ISC",
"bugs": {
"url": "https://github.com/scotch-io/node-routing-course/issues"
},
"homepage": "https://github.com/scotch-io/node-routing-course#readme",
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"morgan": "^1.7.0"
}
}
@@ -1,20 +1,70 @@
// grab packages ==========================================
var app = require('express')(),
port = process.env.PORT || 8080,
morgan = require('morgan'),
bodyParser = require('body-parser');

// configure our app ======================================
// make sure our app can grab data from forms
app.use(bodyParser.urlencoded({ extended: true }));
var app = require('express')(),
port = process.env.PORT || 8080,
morgan = require('morgan'),
bodyParser = require('body-parser');

// log all requests to the console
// configure
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: true }));



// set routes
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});

app.use(authenticate);

app.get('/about', function(req, res) {
res.json({ message: 'i am the about page' });
});

app.get('/contact', function(req, res) {
res.sendFile(__dirname + '/contact.html');
});

app.post('/contact', function(req, res) {
console.log(req.body);
res.send('hello ' + req.body.name + '! Nice to meet you!');
});

app.get('/@:username/:post_slug', checkName, function(req, res) {
console.log(req.params);

// grab user profile
// grab the post

res.send('You are reading ' + req.params.post_slug + ' by ' + req.params.username);
});

// 404
app.use(function(req, res, next) {
res.status(404);
res.sendFile(__dirname + '/404.html');
});

function authenticate(req, res, next) {
// make sure the user is authenticated
// req.params.token

console.log('authenticating user');

next();
}

function checkName(req, res, next) {
console.log(req.params, 'this is the middleware');

// validation
// check the database
// var user = User.findOne({ username: req.params.username });
// if ( ! user)

// route our app ==========================================
app.use(require('./app/routes'));
next();
}

// start the server =======================================
// start the server
app.listen(port, function() {
console.log('App on http://localhost:' + port);
console.log('App listening on http://localhost:' + port);
});

0 comments on commit 61af7a3

Please sign in to comment.
You can’t perform that action at this time.