-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (21 loc) · 825 Bytes
/
server.js
File metadata and controls
30 lines (21 loc) · 825 Bytes
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
"use strict";
/* eslint-disable import/no-extraneous-dependencies, no-console */
const express = require("express");
const { makePolyfill } = require("./handler");
const app = express();
app.use((req, res, next) => {
console.log(`[${new Date().toUTCString()}] ${req.method} ${req.path}`);
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "OPTIONS, GET");
next();
});
app.get("/", (request, response, next) => {
const uaString = request.headers["user-agent"];
makePolyfill({ uaString, cache: false }).then(({ headers, body }) => {
Object.keys(headers).forEach(header => {
response.setHeader(header, headers[header][0].value);
});
response.send(body);
}).catch(next);
});
app.listen(8080, () => console.log("Listening on port 8080..."));