rewrite: uplift the code to typescript, update all deps, refactor for perf and add error handling (#2)
This commit is contained in:
Родитель
082a591337
Коммит
a47ee6f001
|
@ -1,3 +1,5 @@
|
|||
.env
|
||||
.envrc
|
||||
node_modules
|
||||
npm-debug.log
|
||||
lib
|
||||
|
|
33
LICENSE
33
LICENSE
|
@ -1,19 +1,20 @@
|
|||
Copyright (c) 2012 Adam Roben
|
||||
Copyright (c) 2020 Electron Maintainers.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
1
Procfile
1
Procfile
|
@ -1 +0,0 @@
|
|||
web: node pepto-symbol.js
|
17
package.json
17
package.json
|
@ -1,13 +1,22 @@
|
|||
{
|
||||
"name": "pepto-symbol",
|
||||
"name": "@electron/symbol-server",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": "6.9.1"
|
||||
"node": "12"
|
||||
},
|
||||
"dependencies": {
|
||||
"http-proxy": "1.15.2"
|
||||
"http-proxy": "^1.18.1",
|
||||
"uuid": "^8.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node pepto-symbol.js"
|
||||
"build": "tsc",
|
||||
"start": "node lib/index.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/http-proxy": "^1.17.4",
|
||||
"@types/node": "^14.0.13",
|
||||
"@types/uuid": "^8.0.0",
|
||||
"typescript": "^3.9.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
var http = require('http');
|
||||
var httpProxy = require('http-proxy');
|
||||
|
||||
const TARGET_HOST = process.env.S3_BUCKET + '.s3.amazonaws.com';
|
||||
const TARGET = 'http://' + TARGET_HOST;
|
||||
const PATH_PREFIX = process.env.PATH_PREFIX || '';
|
||||
|
||||
// Create a proxy server with custom application logic.
|
||||
var proxy = httpProxy.createProxyServer({});
|
||||
|
||||
// S3 returns 403 errors for files that don't exist. But when symsrv.dll sees a
|
||||
// 403 it blacklists the server for the rest of the debugging session. So we
|
||||
// convert 403s to 404s so symsrv.dll doesn't freak out.
|
||||
proxy.on('proxyReq', function(proxyReq, request, response, options) {
|
||||
var original = response.writeHead;
|
||||
response.writeHead = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
if (args[0] == 403)
|
||||
args[0] = 404;
|
||||
original.apply(response, args);
|
||||
};
|
||||
});
|
||||
|
||||
// S3 determines the bucket from the Host header.
|
||||
proxy.on('proxyReq', function(proxyReq, request, response, options) {
|
||||
proxyReq.setHeader('Host', TARGET_HOST);
|
||||
});
|
||||
|
||||
// symstore.exe and symsrv.dll don't always agree on the case of the path to a
|
||||
// given symbol file. Since S3 URLs are case-sensitive, this causes symbol
|
||||
// loads to fail. To get around this, we assume that the symbols were uploaded
|
||||
// to S3 with all-lowercase keys, and we lowercase all requests we receive to
|
||||
// match.
|
||||
proxy.on('proxyReq', function(proxyReq, request, response, options) {
|
||||
var newPath = proxyReq.path.toLowerCase()
|
||||
// Some symbol servers send + instead of " "
|
||||
// this hacks around that for now
|
||||
newPath = newPath.replace('%2b', '%20')
|
||||
proxyReq.path = PATH_PREFIX + newPath;
|
||||
});
|
||||
|
||||
http.createServer(function(request, response) {
|
||||
proxy.web(request, response, { target: TARGET });
|
||||
}).listen(process.env.PORT);
|
|
@ -0,0 +1,67 @@
|
|||
import assert from 'assert';
|
||||
import * as http from 'http';
|
||||
import httpProxy from 'http-proxy';
|
||||
import * as url from 'url';
|
||||
import * as uuid from 'uuid';
|
||||
|
||||
const { PATH_PREFIX, S3_BUCKET } = process.env;
|
||||
|
||||
assert(S3_BUCKET, 'S3_BUCKET is defined');
|
||||
|
||||
const TARGET_HOST = `${S3_BUCKET}.s3.amazonaws.com`;
|
||||
|
||||
const TARGET_URL = url.format({
|
||||
protocol: 'https:',
|
||||
slashes: true,
|
||||
host: TARGET_HOST,
|
||||
});
|
||||
|
||||
const proxy = httpProxy.createProxyServer({
|
||||
changeOrigin: true,
|
||||
});
|
||||
|
||||
proxy.on('proxyReq', (proxyReq, request, response, options) => {
|
||||
// symstore.exe and symsrv.dll don't always agree on the case of the path to a
|
||||
// given symbol file. Since S3 URLs are case-sensitive, this causes symbol
|
||||
// loads to fail. To get around this, we assume that the symbols were uploaded
|
||||
// to S3 with all-lowercase keys, and we lowercase all requests we receive to
|
||||
// match.
|
||||
let newPath = proxyReq.path.toLowerCase()
|
||||
|
||||
// Some symbol servers send + instead of " "
|
||||
// this hacks around that for now
|
||||
newPath = newPath.replace('%2b', '%20')
|
||||
|
||||
// The symbols may be hosted a deeper path in the S3 bucket
|
||||
// so we prefix the incoming path with that prefix
|
||||
proxyReq.path = `${PATH_PREFIX || ''}${newPath}`;
|
||||
|
||||
// S3 determines the bucket from the Host header
|
||||
proxyReq.setHeader('Host', TARGET_HOST);
|
||||
|
||||
// S3 returns 403 errors for files that don't exist. But when symsrv.dll sees a
|
||||
// 403 it blacklists the server for the rest of the debugging session. So we
|
||||
// convert 403s to 404s so symsrv.dll doesn't freak out.
|
||||
const originalWriteHead = response.writeHead;
|
||||
response.writeHead = (...args: [number, any]) => {
|
||||
if (args[0] == 403)
|
||||
args[0] = 404;
|
||||
return originalWriteHead.apply(response, args);
|
||||
};
|
||||
});
|
||||
|
||||
proxy.on('error', (err, req, res) => {
|
||||
const errorId = uuid.v4();
|
||||
|
||||
console.error('Error:', errorId, 'Request:', req.url, err);
|
||||
|
||||
res.writeHead(500, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
|
||||
res.end(`Something went wrong. If this happens consistently please report to https://github.com/electron/symbol-server with this error ID: "${errorId}"`);
|
||||
});
|
||||
|
||||
http.createServer((req, res) => {
|
||||
proxy.web(req, res, { target: TARGET_URL });
|
||||
}).listen(process.env.PORT || 8080);
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "lib",
|
||||
"lib": [
|
||||
"es6",
|
||||
"es7"
|
||||
],
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/http-proxy@^1.17.4":
|
||||
version "1.17.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.4.tgz#e7c92e3dbe3e13aa799440ff42e6d3a17a9d045b"
|
||||
integrity sha512-IrSHl2u6AWXduUaDLqYpt45tLVCtYv7o4Z0s1KghBCDgIIS9oW5K1H8mZG/A2CfeLdEa7rTd1ACOiHBc1EMT2Q==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/node@*", "@types/node@^14.0.13":
|
||||
version "14.0.13"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.13.tgz#ee1128e881b874c371374c1f72201893616417c9"
|
||||
integrity sha512-rouEWBImiRaSJsVA+ITTFM6ZxibuAlTuNOCyxVbwreu6k6+ujs7DfnU9o+PShFhET78pMBl3eH+AGSI5eOTkPA==
|
||||
|
||||
"@types/uuid@^8.0.0":
|
||||
version "8.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.0.0.tgz#165aae4819ad2174a17476dbe66feebd549556c0"
|
||||
integrity sha512-xSQfNcvOiE5f9dyd4Kzxbof1aTrLobL278pGLKOZI6esGfZ7ts9Ka16CzIN6Y8hFHE1C7jIBZokULhK1bOgjRw==
|
||||
|
||||
debug@^3.0.0:
|
||||
version "3.2.6"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
|
||||
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
|
||||
dependencies:
|
||||
ms "^2.1.1"
|
||||
|
||||
eventemitter3@^4.0.0:
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.4.tgz#b5463ace635a083d018bdc7c917b4c5f10a85384"
|
||||
integrity sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ==
|
||||
|
||||
follow-redirects@^1.0.0:
|
||||
version "1.11.0"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.11.0.tgz#afa14f08ba12a52963140fe43212658897bc0ecb"
|
||||
integrity sha512-KZm0V+ll8PfBrKwMzdo5D13b1bur9Iq9Zd/RMmAoQQcl2PxxFml8cxXPaaPYVbV0RjNjq1CU7zIzAOqtUPudmA==
|
||||
dependencies:
|
||||
debug "^3.0.0"
|
||||
|
||||
http-proxy@^1.18.1:
|
||||
version "1.18.1"
|
||||
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
|
||||
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
|
||||
dependencies:
|
||||
eventemitter3 "^4.0.0"
|
||||
follow-redirects "^1.0.0"
|
||||
requires-port "^1.0.0"
|
||||
|
||||
ms@^2.1.1:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||
|
||||
requires-port@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
|
||||
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
|
||||
|
||||
typescript@^3.9.5:
|
||||
version "3.9.5"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.5.tgz#586f0dba300cde8be52dd1ac4f7e1009c1b13f36"
|
||||
integrity sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==
|
||||
|
||||
uuid@^8.1.0:
|
||||
version "8.1.0"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.1.0.tgz#6f1536eb43249f473abc6bd58ff983da1ca30d8d"
|
||||
integrity sha512-CI18flHDznR0lq54xBycOVmphdCYnQLKn8abKn7PXUiKUGdEd+/l9LWNJmugXel4hXq7S+RMNl34ecyC9TntWg==
|
Загрузка…
Ссылка в новой задаче