-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript17.js
More file actions
29 lines (23 loc) · 757 Bytes
/
script17.js
File metadata and controls
29 lines (23 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var express = require('express');
var path = require('path');
var fs = require('fs');
var app = express();
app.use('/cssFiles', express.static(__dirname + '/files'));
app.get('/', function(req, resp){
resp.sendFile('index.html', {root:path.join(__dirname, './files')});
});
app.get(/^(.+)$/, function(req, resp){
// console.log(path.join(__dirname, './files/', req.params[0], '.html'));
try{
if(fs.statSync(path.join(__dirname, './files/', req.params[0]+ '.html')).isFile()){
resp.sendFile(req.params[0]+'.html', {root: path.join(__dirname, './files')});
}
} catch(err){
console.log(err);
resp.sendFile('404.html', {root: path.join(__dirname, './files')});
}
});
app.listen(1337, function()
{
console.log('listening at port 1337');
});