-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (53 loc) · 1.34 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require("express");
const app = express();
var cors = require("cors");
app.use(cors({ optionsSuccessStatus: 200 }));
app.use(express.static("public"));
app.get((req, res, next) => {
let string = `${req.path} && ${req.method}`;
console.log(string);
next();
});
app.get("/api", (req, res) => {
let string = `${req.path} && ${req.method}`;
console.log(string);
let obj = {
unix: new Date().getTime(),
utc: new Date().toUTCString(),
};
res.json(obj);
});
app.get(
"/api/:date",
(req, res, next) => {
let date;
if (+req.params.date) {
req.params.date = new Date(+req.params.date);
} else {
req.params.date = new Date(req.params.date);
}
next();
},
function (req, res) {
let string = `${req.path} && ${req.method}`;
console.log(string);
let date = req.params.date;
let obj = {};
if (date.toUTCString() !== "Invalid Date")
obj = {
unix: date.getTime(),
utc: date.toUTCString(),
};
else
obj = {
error: "Invalid Date",
};
res.json(obj);
}
);
app.get("/", function (req, res) {
res.sendFile(__dirname + "/views/index.html");
});
var listener = app.listen(3000, function () {
console.log("Your app is listening on port " + listener.address().port);
});