var express = require('express'); var app = express(); var config = require('./config'); var log = function(req, res, next) { console.log(req.ip + " --> " + req.path) next()} app.use(log); app.get('/*foo*', function(req, res) { res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.foo + '</h1></body></html>'); }); app.get('/', function(req, res) { res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.goo + '</h1></body></html>'); }); app.get('/*', function(req, res) { res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.goo + '</h1></body></html>'); }) app.listen(8888, function () { console.log('Listening on port 8888'); }) (Edited: 2017-05-10)
var config = { foo: 'foo', goo: 'goo'} module.exports = config;
var config = require('./config') var express = require('express') var app = express() var log = function (req, res, next) { console.log(req.ip + " --> " + req.path) next()} app.use(log); app.get('/*foo*', function (req, res) {
res.send('<!DOCTYPE html><html><head><title>May 10, 2017</title></head><body>' + config.foo + '</body></html>')}) app.get('*', function (req, res) {
res.send('<!DOCTYPE html><html><head><title>May 10, 2017</title></head><body>' + config.goo + '</body></html>')}) app.listen(8888, function () {
console.log('Server listening on port 8888!')}) (Edited: 2017-05-10)
foo: 'foo', goo: 'goo'
console.log(req.ip) next()} app.use(log); app.get('/*foo*', function (req, res) {
res.send('<!DOCTYPE html><html><head><title>I class excersise</title></head><body>' + config.foo + '</body></html>')}) app.get('*', function (req, res) {
res.send('<!DOCTYPE html><html><head><title>In Class Excersise</title></head><body>' + config.goo + '</body></html>')}) app.listen(8888, function () {
console.log('Server listening on port 8888')})
var config = { foo: 'Entered foo!', goo: 'You got goo instead' } module.exports = config;
var express = require('express'); var app = express(); var config = require('./config');
var logger = function (req, res, next) { console.log("IP: " + req.ip); next(); } app.use(logger);
app.listen(8888, function () { console.log('Server up!') })
app.get('/*foo*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>Foo Page</title></head><body>' + config.foo + '</body></html>'); })
app.get('/*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>Goo Page</title></head><body>' + config.goo + '</body></html>'); })
app.get('/', function (req, res) { res.send('<!DOCTYPE html><html><head><title>Goo Page</title></head><body>' + config.goo + '</body></html>'); })
foo: 'foo', goo: 'goo'} module.exports = config;
console.log(req.ip); next();} app.use(log);
res.send('!<DOCTYPE html><html><body>'+config.foo+'</body></html>')})
res.send('!<DOCTYPE html><html><body>'+config.goo+'</body></html>')});
console.log('Listening to port 8888.')});
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>May 10 In Class Exercise</title> </head><body>' + config.foo + '</body></html>') })
app.get('*', function(req, res) { res.send('<!DOCTYPE html><html><head><title>May 10 In Class Excersise</title> </head><body>' + config.goo +'</body></html>') })
app.listen(8888, function () { console.log('Server up!') })
config.js(Edited: 2017-05-10)
--- var config = { "foo": "foo", "goo": "goo" }; module.exports = config;
-- index.ejs <!DOCTYPE html> <html> <head> <title>In-class Exercise</title> </head> <body> <h1> <%=value%> </h1> </body> </html>
-- app.js
-- var express = require('express'); var path = require('path'); // for directory paths var config = require(path.join(__dirname, 'config')); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // create logger var logger = function(req, res, next) { console.log(req.ip + ": " + req.method); next(); } app.use(logger); // can add different routes app.get('/*foo*', function(req, res) { res.render('index', { 'value': config.foo }); }); // route for everything else app.get('/*', function(req, res) { res.render('index', { 'value': config.goo }); }); app.listen(8888, function() { 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 5/10</title></head><body>' + config.foo + '</body></html>')})
res.send('<!DOCTYPE html><html><head><title>in class 5/10</title></head><body>' + config.goo + '</body></html>')})
console.log('Server up!')})