-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
app.js
43 lines (39 loc) · 1.23 KB
/
app.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const express = require('express')
const path = require("path");
const app = express()
// #############################################################################
// Logs all request paths and method
app.use(function (req, res, next) {
res.set('x-timestamp', Date.now())
res.set('x-powered-by', 'cyclic.sh')
console.log(`[${new Date().toISOString()}] ${req.ip} ${req.method} ${req.path}`);
next();
});
// #############################################################################
// This configures static hosting for files in /public that have the extensions
// listed in the array.
var options = {
dotfiles: 'ignore',
etag: false,
extensions: ['htm', 'html','css','js','ico','jpg','jpeg','png','svg'],
index: ['index.html'],
maxAge: '1m',
redirect: false
}
app.use(express.static('public', options))
// #############################################################################
// Catch all handler for all other request.
app.use('*', (req,res) => {
res.json({
at: new Date().toISOString(),
method: req.method,
hostname: req.hostname,
ip: req.ip,
query: req.query,
headers: req.headers,
cookies: req.cookies,
params: req.params
})
.end()
})
module.exports = app