Name: Pei Liu Student ID: 010200255 === config.js ========= module.exports = { 'foo' : 'this is foo', 'goo' : 'this is goo' } ===== app.js =========== var express = require('express'); var path = require('path'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var index = require('./routes/index'); var users = require('./routes/users'); var config = require('./config.js'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', index); app.use(function(req, res, next) { console.log('your IP Address: 'req.ip + " and route: " + req.path) next() }); app.get('/*foo*', function(req, res) { res.render('index', {'msg' : config.foo}); });
app.get('/', function(req, res) { res.render('index', {'msg' : config.goo}); }); app.get('/*', function(req, res) { res.render('index', {'msg' : config.goo}); });
Name: Luis Otero
var express = require('express'); var path = require('path'); var config = require(path.join(__dirname, 'config')); var app = express();
var log = function(req, res, next){ req.logger_name = "IP logger"; console.log(req.ip); next(); }; app.use(log);
app.get('/*foo*', function(req, res){ res.send("<!DOCTYPE html><html><head><title>"+config.foo+"</title></head><body><h1>"+config.foo+"</h1></body> </html>"); });
app.get('/', function(req, res){ res.send("<!DOCTYPE html><html><head><title>"+config.goo+"</title></head><body><h1>"+config.goo+"</h1></body> </html>"); });
app.get('/*', function(req, res){ res.send("<!DOCTYPE html><html><head><title>"+config.goo+"</title></head><body><h1>"+config.goo+"</h1></body> </html>"); });
app.listen(8888, function(){ console.log("Server is running!"); });
app.js
var express = require('express'); var config = require('config.js'); var app = express();
app.get('/*foo*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>March 10 Exercise</title></head>\n\ <body><div>' + config.foo + '</div></body></html>'); });
app.get('/', function (req, res) { res.send('<!DOCTYPE html><html><head><title>March 10 Exercise</title></head>\n\ <body><div>' + config.goo + '</div></body></html>'); });
app.get('*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>March 10 Exercise</title></head>\n\ <body><div>' + config.goo + '</div></body></html>'); });
var logs = function (req, res, next) { console.log("IP: " + req.ip); next(); // call the next handler };
app.use(logs);
app.listen(8888, function () { console.log('Server up!'); });
config.js
var config = { 'foo': 'foo', 'goo': 'goo' }; module.exports = config;
"foo" : "foo", "goo" : "goo",} module.exports = config;
<title>May 10 In-Class Assignment</title></head> <body>
<div><%=content%></div></body> </html>
console.log("Request IP: " + req.ip + "\n Route: " + req.path); next();} app.use(logger);
res.render('index', { 'content': config.foo});});
res.render('index', { 'content' : config.goo});});
res.render('index', { 'content' : config.goo});});
console.log('Server is up at port 8888!');});
var express = require('express'); var path = require('path'); var config = require(path.join(__dirname, 'config')); var app = express(); var logger = function (req, res, next) { console.log("ip: " + req.ip); next() } app.use(logger); app.get('/*foo*', function(req, res) { res.send('<!DOCTYPE html><html><head><title>In Class Exercise 12</title></head><body><h1>' + config.foo + '</h1></body></html>') }) app.get('*', function(req, res) { res.send('<!DOCTYPE html><html><head><title>In Class Exercise 12</title></head><body><h1>' + config.goo +'</h1></body></html>') }) app.listen(8888, function () { console.log('Server up!') })
Mohnish Kadakia app.js
var express = require('express'); var config = require('config.js'); var app = express();
res.send('<!DOCTYPE html><html><head><title>In class Exercise</title></head><body>' + config.foo + '</body></html>')
res.send('<!DOCTYPE html><html><head><title>In class Exercise</title></head><body>' + config.goo + '</body></html>')
console.log(req.ip); next(); } app.use(logs); app.listen(8888, function () { console.log('server is running'); });
foo: 'foo', goo: 'goo'
console.log("IP address: " + req.ip); next()} app.use(logger);
res.render('index', {'FOO':config.foo});});
res.render('index', {'GOO':config.goo});});
console.log('Server up!')})
console.log(req.ip + " -> " + req.path) next()} app.use(log); app.get('/*foo*', function(req, res){
res.send('<!DOCTYPE html><html><head><title>in class Excercise</title></head><body>' + config.foo + '</body></html>')}) app.get('*', function(req, res){
res.send('<!DOCTYPE html><html><head><title>in class Excercise</title></head><body>' + config.goo + '</body></html>')}) app.listen(8888, function () {
console.log('Server up!')})
var config = { "foo": "foo", "goo": "goo", } module.exports = config;
var express = require('express'); var config = require('./config'); var app = express(); var logger = function (req, res, next) { console.log(req.ip); next() }
app.use(logger); app.get('/*foo*', function(req, res) { res.send('<!DOCTYPE html><html><head><title>InClassExercise</title> </head><body>' + config.foo + '</body></html>') }) app.get('*', function(req, res) { res.send('<!DOCTYPE html><html><head><title>InClassExercise</title> </head><body>' + config.goo +'</body></html>') }) app.listen(8888, function () { console.log('Server up!') })
foo: 'foo', goo: 'goo'
console.log(req.ip + " --> " + req.path) next()}; app.use(log);
res.send('<!DOCTYPE html><html><head><title>In class exercise 10th May, 2017</title></head><body>' + config.foo + '</body></html>')});
res.send('<!DOCTYPE html><html><head><title>In class exercise 10th May, 2017</title></head><body>' + config.goo + '</body></html>')});
console.log('Server listening on port 8888!')});