-
-
Save KamuelaFranco/f7b345af1ddfcda8f22746441bd9d8d4 to your computer and use it in GitHub Desktop.
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
var Express = require('express'); | |
var path = require('path'); | |
var app = Express(); | |
var fs = require('fs'); | |
console.log(__dirname); | |
app.use('/cssFiles', express.static(__dirname + '/assets')); | |
app.get('/', function(req, res) { | |
res.sendFile('index.html', {root: path.join(__dirname, './files')}); | |
}); | |
app.get(/^(.+)$/, function(req,res) { | |
console.log(req.params); | |
try { | |
if(!fs.statSync(path.join(__dirname, './files/', req.params[0]+'.html')).isFile()) { | |
throw new Error('File Not Found'); | |
} | |
res.sendFile(req.params[0]+'.html', {root: path.join(__dirname, './files')}); | |
} catch(err) { | |
console.log(err); | |
res.sendFile('404.html', {root: path.join(__dirname, './files')}); | |
} | |
}); | |
app.listen(1337, function() { | |
console.log('listening at 1337'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment