-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Feat: add traffic mesh proxy flag #1196
Conversation
@@ -0,0 +1,90 @@ | |||
const fs = require('fs-extra') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the logic here was extracted from https://github.com/netlify/cli/blob/93468a3fc43db5d637b30b9cbb21042da8626962/src/utils/live-tunnel.js
And made generic so we can re-use it.
}) | ||
return outdated | ||
} catch (e) { | ||
if (exists) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a small fix to use existing version if checking for updates failed.
That can happen when reaching GitHub API limit:
netlify/gh-release-fetch#3
} | ||
}) | ||
|
||
const packages = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit strange to have this here and not in a dedicated test file (one for the tunnel client and one for the traffic mesh).
However I prefer it this way since we're actually testing the exec-fetcher
@@ -0,0 +1,15 @@ | |||
const path = require('path') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started a new concept of libs
instead of utils
that we currently have.
It seems that most of our current utils
are not used for sharing code, but just to extract functionality from the different commands.
However some commands/utils need to share the same code - so I started putting those parts under lib.
if (isWindows()) { | ||
return true | ||
} | ||
const startLiveTunnel = async ({ siteId, netlifyApiToken, localPort, log }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createTunnel
and connectTunnel
were called separately in the dev command.
I grouped them into startLiveTunnel
@@ -0,0 +1,346 @@ | |||
const path = require('path') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was mostly copied as is from the dev
command
@@ -384,8 +29,11 @@ async function startDevServer(settings, log) { | |||
}, | |||
}) | |||
|
|||
server.start(function() { | |||
log(`\n${NETLIFYDEVLOG} Server listening to`, settings.frameworkPort) | |||
await new Promise(resolve => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some code to wait until the server is ready
} | ||
|
||
async function startProxy(settings = {}, addonUrls, configPath, projectDir) { | ||
const functionsServer = settings.functionsPort ? `http://localhost:${settings.functionsPort}` : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original startProxy
had some code to wait for the framework server port and functions server port:
Line 170 in 93468a3
try { |
Line 178 in 93468a3
if (functionsDir && settings.functionsPort) { |
I removed it in favour of:
- Using
waitPort
in the function that starts the framework server: https://github.com/netlify/cli/pull/1196/files#diff-8a2f65e3aede3ea9696e546766f50f03R82 - When starting the functions server - wait on a promise until the server is ready: https://github.com/netlify/cli/pull/1196/files#diff-cf2bd94d7688f0711bbd931e6c5e0397R373
proxy.ws(req, socket, head) | ||
}) | ||
|
||
return new Promise(resolve => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also added this code to wait for the dev server to be ready
|
||
return new Promise(resolve => { | ||
server.listen({ port: settings.port }, () => { | ||
resolve(`http://localhost:${settings.port}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original startProxy
returned an object with url
and port
as properties:
Line 235 in 93468a3
return { url: `http://localhost:${settings.port}`, port: settings.port } |
but only
url
was used.Simplified the function to return just the
url
as a string
@@ -318,4 +310,77 @@ async function serveFunctions(dir, siteInfo = {}) { | |||
return app | |||
} | |||
|
|||
module.exports = { serveFunctions } | |||
const getBuildFunction = ({ functionBuilder, log }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this chunk of code from the dev
command
const functionsServer = await serveFunctions(settings.functions, siteInfo) | ||
|
||
await new Promise(resolve => { | ||
functionsServer.listen(settings.functionsPort, err => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to wait until the server is ready
@@ -0,0 +1,70 @@ | |||
const path = require('path') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very similar to the tunnel client code
) | ||
|
||
try { | ||
const open = await waitPort({ port, output: 'silent', timeout: 30 * 1000 }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait for the agent to be ready (the traffic mesh agent writes to a log file and not stdout) so waiting on the port works well.
path: 'index.html', | ||
content: '<h1>⊂◉‿◉つ</h1>', | ||
}) | ||
const testMatrix = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file is for support a test matrix with different args (and creating unique test names)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
@ehmicky wow that was fast. Going to disable the new failing test (they are failing to due GitHub API limit reached on CI). |
Fixes https://github.com/netlify/traffic-mesh/issues/806
This is a big PR since I did some refactoring to the dev command in the process since it was very hard to follow.
The commits are small though.
I'll add comments to clarify the changes.
This PR consists of 3 main changes: