-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
34 lines (30 loc) · 872 Bytes
/
server.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
const express = require('express');
const app = express();
var port = process.env.PORT || 8000;
function getMilSec(time) {
var mills = time.getTime();
if(mills){
return mills;
}else{
return null;
}
}
function getNormTime(time) {
var year = time.getFullYear(),
month = time.getMonth(),
day = time.getDate(),
monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"],
longMonth = monthNames[month];
if(day && longMonth && year){
return `"${day} ${longMonth} ${year}"`;
}else{
return null;
}
}
app.get('*', ((req, res) => {
var request = new Date(req.originalUrl.replace(/^\//, ''));
res.send(`{ "unix": ${getMilSec(request)}, "natural": ${getNormTime(request)} }`);
}));
app.listen(port);
console.log('server is running...');