diff --git a/Dockerfile b/Dockerfile index 693a34687..10bff339a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN : \ # build && make build_prod \ # place the runtime application in /app - && mv dist corsProxy.js index.js env.js plugins.js /app + && mv dist index.js env.js plugins.js /app FROM gcr.io/distroless/nodejs LABEL org.opencontainers.image.source https://github.com/lyft/flyteconsole diff --git a/corsProxy.js b/corsProxy.js deleted file mode 100644 index 3ddfdfe94..000000000 --- a/corsProxy.js +++ /dev/null @@ -1,49 +0,0 @@ -const http = require('http'); -const https = require('https'); -const url = require('url'); - -/** Mounts a proxy at `basePath` such that requests of the form - * `${basePath}/http://www.example.com?queryString=value` will be converted to - * `http://www.example.com?queryString=value`, preserving any request headers. - * The response is piped directly to the client with no processing. - */ -module.exports = function corsProxy(basePath) { - const pathOffset = basePath.length; - return function (req, res, next) { - const pathIndex = req.url.indexOf(basePath); - // base path doesn't match, ignore - if (pathIndex < 0) { - return next(); - } - - const targetUrl = req.url.substring(pathIndex + pathOffset + 1); - const config = url.parse(targetUrl); - config.method = req.method; - - // We need to use a different request class depending on the - // protocol - const handler = config.protocol === 'https:' ? https : http; - - const proxyReq = handler.request(config, function (proxyRes) { - res.writeHead(proxyRes.statusCode, proxyRes.headers); - proxyRes.pipe(res, { - end: true, - }); - }); - - proxyReq.on('error', (err) => res.status(500).send(err)); - - // Copy over all headers except for 'Host', since that value would - // point to *this* server, and not the remote server. - Object.keys(req.headers).forEach((key) => { - if (key.toLowerCase() === 'host') { - return; - } - proxyReq.setHeader(key, req.headers[key]); - }); - - req.pipe(proxyReq, { - end: true, - }); - }; -}; diff --git a/index.js b/index.js index fd487f746..b25891527 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,6 @@ const morgan = require('morgan'); const express = require('express'); const env = require('./env'); const { applyMiddleware } = require('./plugins'); -const corsProxy = require('./corsProxy.js'); const app = express(); @@ -16,7 +15,6 @@ const app = express(); app.use(morgan('combined')); app.use(express.json()); app.get(`${env.BASE_URL}/healthz`, (_req, res) => res.status(200).send()); -app.use(corsProxy(`${env.BASE_URL}${env.CORS_PROXY_PREFIX}`)); if (typeof applyMiddleware === 'function') { console.log('Found middleware plugins, applying...');