-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
[feat] added cloudflare static tunnels support #282
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Looks pretty good! Just have a few questions on the execution of things.
Only required changes are using the PORT
environment variable when applicable and running the new code through Prettier for format consistency.
"ingress": [ | ||
{ | ||
"hostname": `robo.${process.env.CLOUDFLARE_DOMAIN}`, | ||
"service": "http://localhost:3000" |
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.
Local service port should be process.env.PORT
by default if that 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.
Fixed. Port will default to 3000 if none is set in the .env file
cloudflareLogger.debug(`Updated .env file with ${key}=${value}`) | ||
} | ||
|
||
function installService(token: string) { |
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.
Do we really want to install cloudflared
as a service on the user machine even though startCloudflared
already runs the tunnel associated with that token?
export function startCloudflared(url: string) { | ||
const tunnelId = process.env.CLOUDFLARE_TUNNEL_ID; | ||
const tunnelToken = process.env.CLOUDFLARE_TUNNEL_TOKEN; |
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.
Can we reduce the number of items requested from the user by requesting the tunnel token from Cloudflare ourselves?
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.
Currently only the Account ID, API Key, and the domain are requested from the user. The tunnel ID and token are stored in the .env file after the initial tunnel creation for later use.
const tunnelToken = process.env.CLOUDFLARE_TUNNEL_TOKEN; | ||
const tunnelDomain = process.env.CLOUDFLARE_DOMAIN; | ||
|
||
const commandArgs = (tunnelId && tunnelToken && tunnelDomain) ? ['tunnel', '--no-autoupdate', 'run', '--token', tunnelToken, '--url', url, tunnelId] : ['tunnel', '--url', url, '--no-autoupdate']; |
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 ternary operation is a bit tough to read quickly. Mind cleaning it by appending the token conditionally instead? The code overall would be longer but more legible.
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.
Refactored for easier readability
|
||
try { | ||
if (process.env.CLOUDFLARE_TUNNEL_ID) { | ||
const roboTunnel = await cloudflareRequest(`/accounts/${process.env.CLOUDFLARE_ACCOUNT_ID}/cfd_tunnel/${process.env.CLOUDFLARE_TUNNEL_ID}/token`); |
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.
Do Cloudflare's tunnel tokens expire at some point? If so, do we have a way to auto refresh them?
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 was unable to find any documentation that would hint that they expire or any endpoints that let us refresh them.
This pertains to #276