-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (24 loc) · 825 Bytes
/
index.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
const express = require("express"),
app = express(),
bodyParser = require("body-parser");
// support parsing of application/json type post data
app.use(bodyParser.json());
//support parsing of application/x-www-form-urlencoded post data
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/api/whoami/", (req, res) => {
const ip = req.connection.remoteAddress;
const parseData = {
ipaddress: ip.split(":").reverse()[0],
language: req.headers["accept-language"],
software: req.headers["user-agent"]
};
res.json(parseData);
});
app.use(express.static("public"));
app.get("/", (request, response) => {
response.sendFile(`${__dirname}/views/index.html`);
});
const portNumber = process.env.PORT || 8080;
app.listen(portNumber, () => {
console.log(`listening on port ${portNumber}`);
});