Skip to content

Commit

Permalink
Merge pull request #358 from conwnet/master
Browse files Browse the repository at this point in the history
release 0.6.1
  • Loading branch information
conwnet authored Sep 14, 2021
2 parents dad32b3 + 5bee673 commit 8879a31
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 55 deletions.
11 changes: 9 additions & 2 deletions api/vscode-unpkg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ module.exports = async (req, res) => {
const publisher = matches[1];
const restPartsPath = matches[2];
const requestUrl = `https://${publisher}.vscode-unpkg.net/${publisher}/${restPartsPath}`;
const response = await got.get(requestUrl);
const responsePromise = got(requestUrl);
const bufferPromise = responsePromise.buffer();
const [response, buffer] = await Promise.all([
responsePromise,
bufferPromise,
]);

res.status(response.statusCode);
return res.send(response.body);
res.setHeader('cache-control', response.headers['cache-control']);
res.setHeader('content-type', response.headers['content-type']);
return res.send(buffer);
};
18 changes: 9 additions & 9 deletions api/vscode-unpkg/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


"@sindresorhus/is@^4.0.0":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.0.1.tgz#d26729db850fa327b7cacc5522252194404226f5"
integrity sha512-Qm9hBEBu18wt1PO2flE7LPb30BHMQt1eQgbV76YntdNk73XZGpn3izvGTYxbGgzXKgbCjiia0uxTd3aTNQrY/g==
version "4.1.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.1.0.tgz#3853c0c48b47f0ebcdd3cd9a66fdd0d277173e78"
integrity sha512-Cgva8HxclecUCmAImsWsbZGUh6p5DSzQ8l2Uzxuj9ANiD7LVhLM1UJ2hX/R2Y+ILpvqgW9QjmTCaBkXtj8+UOg==

"@szmarczak/http-timer@^4.0.5":
version "4.0.6"
Expand All @@ -30,16 +30,16 @@
integrity sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==

"@types/keyv@*":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.2.tgz#5d97bb65526c20b6e0845f6b0d2ade4f28604ee5"
integrity sha512-/FvAK2p4jQOaJ6CGDHJTqZcUtbZe820qIeTg7o0Shg7drB4JHeL+V/dhSaly7NXx6u8eSee+r7coT+yuJEvDLg==
version "3.1.3"
resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.3.tgz#1c9aae32872ec1f20dcdaee89a9f3ba88f465e41"
integrity sha512-FXCJgyyN3ivVgRoml4h94G/p3kY+u/B86La+QptcqJaWtBWtmc6TtkNfS40n9bIvyLteHh7zXOtgbobORKPbDg==
dependencies:
"@types/node" "*"

"@types/node@*":
version "16.7.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.7.10.tgz#7aa732cc47341c12a16b7d562f519c2383b6d4fc"
integrity sha512-S63Dlv4zIPb8x6MMTgDq5WWRJQe56iBEY0O3SOFA9JrRienkOVDXSXBjjJw6HTNQYSE2JI6GMCR6LVbIMHJVvA==
version "16.9.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.9.1.tgz#0611b37db4246c937feef529ddcc018cf8e35708"
integrity sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==

"@types/responselike@*", "@types/responselike@^1.0.0":
version "1.0.0"
Expand Down
38 changes: 15 additions & 23 deletions scripts/serve-dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ const handler = require('serve-handler');
const httpProxy = require('http-proxy');

const APP_ROOT = path.join(__dirname, '..');
const options = { public: path.join(APP_ROOT, 'dist'), cleanUrls: false };

// now sourcegraph graphql api is refused the CORS check
// just proxy the request to sourcegraph directly for a taste
const sourcegraphProxy = httpProxy.createProxyServer({
target: 'https://sourcegraph.com/.api/graphql',
const staticOptions = { public: path.join(APP_ROOT, 'dist'), cleanUrls: false };
const proxyServer = httpProxy.createServer({
ignorePath: true,
changeOrigin: false,
headers: {
host: 'sourcegraph.com',
},
});

const handleProxyError = (error) => {
Expand All @@ -27,26 +20,25 @@ const handleProxyError = (error) => {
});
res.end(JSON.stringify({ message: error.message }));
};
proxyServer.on('error', handleProxyError);

// now sourcegraph graphql api is refused the CORS check
// just proxy the request to sourcegraph directly for a taste
const sourcegraphProxyHandler = (req, res) => {
sourcegraphProxy.web(req, res);
sourcegraphProxy.on('error', handleProxyError);
const host = 'sourcegraph.com';
const target = `https://${host}/.api/graphql`;
const headers = { host };
proxyServer.web(req, res, { target, headers });
};

// proxy the request to vscode-unpkg.net
const vscodeUnpkgProxyHandler = (req, res, vscodeUnpkgMatches) => {
const publisher = vscodeUnpkgMatches[1];
const restPartsPath = vscodeUnpkgMatches[2];
const host = `${publisher}.vscode-unpkg.net`;
const proxy = httpProxy.createServer({
target: `https://${host}/${publisher}/${restPartsPath}`,
ignorePath: true,
changeOrigin: false,
headers: { host },
});

proxy.web(req, res);
proxy.on('error', handleProxyError);
const host = `${publisher}.vscode-unpkg.net`.toLowerCase();
const target = `https://${host}/${publisher}/${restPartsPath}`;
const headers = { host };
proxyServer.web(req, res, { target, headers });
};

const server = http.createServer((request, response) => {
Expand All @@ -66,11 +58,11 @@ const server = http.createServer((request, response) => {
fs.constants.F_OK,
(error) => {
if (!error && urlObj.pathname !== '/') {
return handler(request, response, options);
return handler(request, response, staticOptions);
}
return handler(request, response, {
rewrites: [{ source: '*', destination: '/index.html' }],
...options,
...staticOptions,
});
}
);
Expand Down
16 changes: 8 additions & 8 deletions tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -833,11 +833,11 @@ aws4@^1.8.0:
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==

axios@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.10.0"
follow-redirects "^1.14.0"

babel-jest@^26.6.3:
version "26.6.3"
Expand Down Expand Up @@ -1722,10 +1722,10 @@ find-up@^4.0.0, find-up@^4.1.0:
locate-path "^5.0.0"
path-exists "^4.0.0"

follow-redirects@^1.10.0:
version "1.13.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147"
integrity sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==
follow-redirects@^1.14.0:
version "1.14.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.3.tgz#6ada78118d8d24caee595595accdc0ac6abd022e"
integrity sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==

for-in@^1.0.2:
version "1.0.2"
Expand Down
21 changes: 8 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ at-least-node@^1.0.0:
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==

axios@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.10.0"
follow-redirects "^1.14.0"

balanced-match@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -857,15 +857,10 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469"
integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA==

follow-redirects@^1.0.0:
version "1.13.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267"
integrity sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==

follow-redirects@^1.10.0:
version "1.13.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147"
integrity sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==
follow-redirects@^1.0.0, follow-redirects@^1.14.0:
version "1.14.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.3.tgz#6ada78118d8d24caee595595accdc0ac6abd022e"
integrity sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==

from@~0:
version "0.1.7"
Expand Down

1 comment on commit 8879a31

@vercel
Copy link

@vercel vercel bot commented on 8879a31 Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.