Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(command-dev): use waitPort built-in http request support #2842

Merged
merged 3 commits into from
Jul 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const { promisify } = require('util')
const { flags: flagsLib } = require('@oclif/command')
const boxen = require('boxen')
const chalk = require('chalk')
const fetch = require('node-fetch')
const waitFor = require('p-wait-for')
const StaticServer = require('static-server')
const stripAnsiCc = require('strip-ansi-control-characters')
const waitPort = require('wait-port')
Expand All @@ -24,11 +22,6 @@ const openBrowser = require('../../utils/open-browser')
const { startProxy } = require('../../utils/proxy')
const { startForwardProxy } = require('../../utils/traffic-mesh')

// 1 second
const SERVER_POLL_INTERVAL = 1e3
// 20 seconds
const SERVER_POLL_TIMEOUT = 2e4

const startStaticServer = async ({ settings, log }) => {
const server = new StaticServer({
rootPath: settings.dist,
Expand Down Expand Up @@ -93,35 +86,12 @@ const startFrameworkServer = async function ({ settings, log, exit }) {
port: settings.frameworkPort,
output: 'silent',
timeout: FRAMEWORK_PORT_TIMEOUT,
...(settings.disableLocalServerPolling ? {} : { protocol: 'http' }),
Copy link
Contributor Author

@erezrokah erezrokah Jul 5, 2021

Choose a reason for hiding this comment

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

This option is documented via the library types and somehow here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eduardoboucas can you verify this doesn't break the original fix (I remember you had issues with this when running create-react-app).

Copy link
Member

Choose a reason for hiding this comment

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

@eduardoboucas can you verify this doesn't break the original fix (I remember you had issues with this when running create-react-app).

It seems to work fine! I remember the issue was with a Gatsby site and I'm not able to replicate it using this branch.

})

if (!open) {
throw new Error(`Timed out waiting for port '${settings.frameworkPort}' to be open`)
}

if (!settings.disableLocalServerPolling) {
const waitForServerToRespond = async () => {
try {
await fetch(`http://localhost:${settings.frameworkPort}`, {
method: 'HEAD',
timeout: SERVER_POLL_INTERVAL,
})
} catch (_) {
return false
}

return true
}

try {
await waitFor(waitForServerToRespond, {
interval: SERVER_POLL_INTERVAL,
timeout: SERVER_POLL_TIMEOUT,
})
} catch (_) {
log(NETLIFYDEVWARN, 'Netlify Dev could not verify that your framework server is responding to requests.')
}
}
} catch (error) {
log(NETLIFYDEVERR, `Netlify Dev could not connect to localhost:${settings.frameworkPort}.`)
log(NETLIFYDEVERR, `Please make sure your framework server is running on port ${settings.frameworkPort}`)
Expand Down