filesafe/routes/routes.js

89 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-01-14 08:50:18 +00:00
const config = require('../config.js')
const routes = require('express').Router()
const path = require('path')
2017-01-14 08:50:18 +00:00
routes.get('/', (req, res) => {
let options = {
root: 'pages/',
dotfiles: 'deny',
headers: {
'x-timestamp': Date.now(),
'x-sent': true
}
}
res.sendFile('home.html', options, function (err) {
if (err) {
console.log(err)
res.status(err.status).end()
} else {
console.log('Sent: home.html')
}
})
})
routes.get('/admin', function (req, res, next) {
let options = {
root: 'pages/admin/',
dotfiles: 'deny',
headers: {
'x-timestamp': Date.now(),
'x-sent': true
}
}
res.sendFile('index.html', options, function (err) {
if (err) {
console.log(err)
res.status(err.status).end()
} else {
console.log('Sent: index.html')
}
})
})
routes.get('/admin/:name', function (req, res, next) {
let options = {
root: 'pages/admin/',
dotfiles: 'deny',
headers: {
'x-timestamp': Date.now(),
'x-sent': true
}
}
let fileName = req.params.name
res.sendFile(fileName, options, function (err) {
if (err) {
console.log(err)
res.status(err.status).end()
} else {
console.log('Sent:', fileName)
}
})
})
/*
routes.get('/', (req, res) => {
res.sendFile('pages/home.html')
})
routes.get('/dashboard', (req, res, next) => {
2017-01-14 08:51:56 +00:00
if(config.TOKEN !== '')
if(req.headers.auth !== config.TOKEN)
return res.status(401).send('not-authorized')
return res.sendFile('pages/home.html')
2017-01-14 08:50:18 +00:00
})
*/
2017-01-14 08:50:18 +00:00
module.exports = routes