Skip to content

Commit 77e57fd

Browse files
committed
add download
1 parent 65e074c commit 77e57fd

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

api/download.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const fetch = require('node-fetch');
4+
5+
const authorization = `Bearer ${process.env.GH_TOKEN}`;
6+
7+
module.exports = (req, res) => {
8+
if (req.method === 'OPTIONS') {
9+
res.writeHead(200, { 'Allow': 'OPTIONS, GET' });
10+
res.end();
11+
return res;
12+
}
13+
if (req.method !== 'GET') {
14+
return res.status(405).send('405');
15+
}
16+
17+
delete req.headers.host;
18+
return fetch('https://npm.pkg.github.com/@engine262/engine262', {
19+
headers: { ...req.headers, authorization },
20+
})
21+
.then((r) => r.json())
22+
.then((r) => {
23+
const link = r.versions[r['dist-tags'].latest].dist.tarball;
24+
return fetch(link, {
25+
redirect: 'manual',
26+
headers: { authorization },
27+
}).then((r2) => {
28+
res.status(302);
29+
res.setHeader('location', r2.headers.get('location'));
30+
return res.end();
31+
});
32+
});
33+
};

now.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
{
1818
"src": "/engine262/engine262.js.map",
1919
"dest": "/api/bridge.js"
20+
},
21+
{
22+
"src": "/download",
23+
"dest": "/api/download.js"
2024
}
2125
],
2226
"env": {

0 commit comments

Comments
 (0)