Skip to content

Commit

Permalink
fix: proxy server for Node.js 17/18 (#4835)
Browse files Browse the repository at this point in the history
* fix: proxy server for Node.js 17/18

* fix(tests): try something

* fix(tests): use hardcoded IP
  • Loading branch information
anmonteiro committed Jul 22, 2022
1 parent d522c2d commit 76ee52f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/utils/proxy.js
Expand Up @@ -279,7 +279,7 @@ const initializeProxy = async function ({ configPath, distDir, port, projectDir
const proxy = httpProxy.createProxyServer({
selfHandleResponse: true,
target: {
host: 'localhost',
host: '127.0.0.1',
port,
},
})
Expand Down Expand Up @@ -349,7 +349,7 @@ const initializeProxy = async function ({ configPath, distDir, port, projectDir
}

const responseData = []
const requestURL = new URL(req.url, `http://${req.headers.host || 'localhost'}`)
const requestURL = new URL(req.url, `http://${req.headers.host || '127.0.0.1'}`)
const headersRules = headersForPath(headers, requestURL.pathname)

proxyRes.on('data', function onData(data) {
Expand Down Expand Up @@ -392,7 +392,7 @@ const initializeProxy = async function ({ configPath, distDir, port, projectDir

const handlers = {
web: (req, res, options) => {
const requestURL = new URL(req.url, 'http://localhost')
const requestURL = new URL(req.url, 'http://127.0.0.1')
req.proxyOptions = options
req.alternativePaths = alternativePathsFor(requestURL.pathname).map((filePath) => filePath + requestURL.search)
// Ref: https://nodejs.org/api/net.html#net_socket_remoteaddress
Expand Down Expand Up @@ -428,7 +428,7 @@ const onRequest = async ({ addonsUrls, edgeFunctionsProxy, functionsServer, prox
const options = {
match,
addonsUrls,
target: `http://localhost:${settings.frameworkPort}`,
target: `http://127.0.0.1:${settings.frameworkPort}`,
publicFolder: settings.dist,
functionsServer,
functionsPort: settings.functionsPort,
Expand Down Expand Up @@ -474,7 +474,7 @@ const startProxy = async function ({
settings,
state,
}) {
const functionsServer = settings.functionsPort ? `http://localhost:${settings.functionsPort}` : null
const functionsServer = settings.functionsPort ? `http://127.0.0.1:${settings.functionsPort}` : null
const edgeFunctionsProxy = await edgeFunctions.initializeProxy({
config,
configPath,
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/400.command.dev.test.js
Expand Up @@ -8,8 +8,6 @@ const avaTest = require('ava')
const { isCI } = require('ci-info')
const FormData = require('form-data')

const { originalIP } = require('../lib/local-ip')

const { withDevServer } = require('./utils/dev-server')
const got = require('./utils/got')
const { withSiteBuilder } = require('./utils/site-builder')
Expand Down Expand Up @@ -407,7 +405,7 @@ test('should handle form submission', async (t) => {
payload: {
created_at: body.payload.created_at,
data: {
ip: originalIP,
ip: '::ffff:127.0.0.1',
some: 'thing',
user_agent: 'got (https://github.com/sindresorhus/got)',
},
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/500.command.dev.test.js
Expand Up @@ -7,8 +7,6 @@ const avaTest = require('ava')
const { isCI } = require('ci-info')
const FormData = require('form-data')

const { originalIP } = require('../lib/local-ip')

const { withDevServer } = require('./utils/dev-server')
const got = require('./utils/got')
const { withSiteBuilder } = require('./utils/site-builder')
Expand Down Expand Up @@ -102,7 +100,7 @@ test('should handle form submission', async (t) => {
payload: {
created_at: body.payload.created_at,
data: {
ip: originalIP,
ip: '::ffff:127.0.0.1',
some: 'thing',
user_agent: 'got (https://github.com/sindresorhus/got)',
},
Expand Down

1 comment on commit 76ee52f

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

Package size: 222 MB

Please sign in to comment.