-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
31 lines (26 loc) · 864 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
30
31
const { getResponseData } = require('@chickaree/web');
const { buffer, send } = require('micro');
const { decode } = require('base64url');
const fetch = require('node-fetch');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const { Response } = fetch;
// Setup Globals
const { window } = new JSDOM('');
global.DOMParser = window.DOMParser;
global.HTMLDocument = window.HTMLDocument;
global.XMLDocument = window.XMLDocument;
module.exports = async (req, res) => {
if (req.method !== 'POST') {
return send(res, 405);
}
const [domain, hash] = req.url.substring(1).split('/');
const url = new URL(hash ? decode(hash) : '', `https://${domain}/`);
const response = new Response(await buffer(req), {
url: url.toString(),
headers: {
'Content-Type': req.headers['content-type'],
},
});
return getResponseData(response);
};