Closed bobzilladev closed 1 year ago
Few pieces of feedback:
degit
for cloning and running an example: npx degit github:user/repo/directory/sub-directory#branch-name <folder-name>
then npm i
Framework Specific:
Express
nodemon
?Fastify
ngrok
libraryasync/await
and methods not builder patternExample of listening then attaching ngrok with async/await:
// Listen to server
server.listen(port, async function () {
// Start ngrok process
if (process.env.NGROK_TOKEN) {
await ngrok.authtoken(process.env.NGROK_TOKEN);
url = await ngrok.connect(port);
}
console.log(`Server is listening on ${port}!`)
console.log(`Server available at ${url}`)
})
Hapi
Koa
Nest
Nextjs
parseInt(process.env.PORT, 10) || 3000
as per this example since they get established as env variables.Remix / Nextjs / Svelte
ngrok
logic into it's own file and requiring it inside the config file to keep things clean.@nijikokun Thanks for all the feedback! I've pushed a commit that hopefully addresses everything.
Each example should be self-contained project in it's own folder similar to Prisma and NextJS examples.
Migrated to this layout.
Point users to use degit for cloning and running an example: npx degit github:user/repo/directory/sub-directory#branch-name
then npm i
Added info to Examples section of README.md
.
Express: What local port is this running on?
Added logging of socket address.
Express: How do I run multiple express servers with this?
Can call listen(app)
with multiple app's and each will forward on a separate generated pipe/tcp socket.
Express: How does this work with something like
nodemon
?
Looks like nodemon
restarts the entire node process, so would want to use tunnel with domain
to have a deterministic domain to iterate on.
Start the server listener then point ngrok.
Have reordered the setup calls in Fastify, Hapi, and Nest.
Fastify: I would also expect to use async/await.
Moved ngrok setup into async block to use await
rather than promise methods.
Koa: require...would move to the top of the file
Moved.
Next: Make tunnel is weird, should probably be based on ENV variable.
Unfortunately Next first runs a child process to build, then the parent does its setup, so an environment variable can't maintain a single tunnel. I've added a comment around this non-intuitive behavior.
Next: Port and host...as env variables.
Caught PORT
in Remix but missed in Next, have added. There doesn't appear to be Next support for host
via env.
Would suggest putting ngrok logic into it's own file and requiring it inside the config file to keep things clean.
Moved logic to ngrok.config files in Next.js, Remix, Svelt, and Vue examples and updated README.
The changes look great! Nice work!
Just looks like there are some leftover files in the examples directory (node modules and package.json)?
I've removed the node_modules
symlink. Kept the package.json
for the basic single-file examples which need ngrok, ts-node, and winston.
Almost all the files in this PR are auto-generated by the various frameworks, but are necessary to test the actual example code. The following files linked to in the README.md are the new ngrok pieces: