Created
July 22, 2016 14:05
-
-
Save johnbeech/35cd76c7720068ca6bd262b823eb8605 to your computer and use it in GitHub Desktop.
Experiment in testing /'s on routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Express server - Testing /'s on routes | |
* npm i express | |
* node server.js | |
*/ | |
const express = require('express'); | |
const app = express(); | |
app.use('/test/one/', function(req, res) { | |
const result = 'Result B'; | |
res.send({ | |
url: req.originalUrl, | |
result | |
}); | |
}); | |
app.use('/test/one', function(req, res) { | |
const result = 'Result A'; | |
res.send({ | |
url: req.originalUrl, | |
result | |
}); | |
}); | |
app.use('/test/two/', function(req, res) { | |
const result = (req.originalUrl === '/test/two/') ? 'Result C' : 'Result D'; | |
res.send({ | |
url: req.originalUrl, | |
result | |
}); | |
}); | |
app.use('/test/three.json', function(req, res) { | |
const result = 'Result E'; | |
res.send({ | |
url: req.originalUrl, | |
result | |
}); | |
}); | |
app.listen(3000, function() { | |
console.log('Example app listening on port 3000!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment