File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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" : {
You can’t perform that action at this time.
0 commit comments