Skip to content

Feat: Detect if a Next.js project is running on the specified port before opening a tunnel - #214

Merged
matt-aitken merged 4 commits into
triggerdotdev:mainfrom
Ashutosh-Bhadauriya:feature/detect-next-project
Jul 31, 2023
Merged

Feat: Detect if a Next.js project is running on the specified port before opening a tunnel#214
matt-aitken merged 4 commits into
triggerdotdev:mainfrom
Ashutosh-Bhadauriya:feature/detect-next-project

Conversation

@Ashutosh-Bhadauriya

@Ashutosh-Bhadauriya Ashutosh-Bhadauriya commented Jul 25, 2023

Copy link
Copy Markdown
Contributor

Fixes #210
/claim #210

Detect if a Next.js project is running on the specified port before opening a tunnel

@changeset-bot

changeset-bot Bot commented Jul 25, 2023

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f006d67

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@trigger.dev/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Ashutosh-Bhadauriya Ashutosh-Bhadauriya changed the title [WIP]Feat: Detect nextjs project [WIP]Feat: Detect if a Next.js project is running on the specified port before opening a tunnel Jul 25, 2023
@Ashutosh-Bhadauriya

Copy link
Copy Markdown
Contributor Author

@ericallam I have done the changes, but not sure how to test it.

What i'm doing right now?
Start trigger app and don't start the nextjs app, then it should show in terminal right? Or I've misunderstood the issue?

@ericallam

Copy link
Copy Markdown
Member

This looks good to me. Basically we want to actually make sure there is a local server running with the Trigger.dev client configured correctly before we call resolveEndpointUrl.

To test it, you should first build the CLI and watch for changes:

cd packages/cli
pnpm run dev

Open a new Terminal window and run the webapp locally and then create a new project in the dashboard. Copy out the dev API key.

Next, create a new (temporary) nextjs app in the examples directory:

pnpm create next-app@latest

Follow the prompts to create a TypeScript project using the App Dir.

Then once that's finished, add the @trigger.dev/cli to the devDependencies of the newly created Next.js app package.json file, like so:

{
  "devDependencies": { "@trigger.dev/cli": "workspace:*" }
}

Then you should (in a new Terminal window) cd into the example and do the following:

cd examples/your-newly-created-nextjs-project
pnpm i
pnpm exec trigger-cli init

Select self-hosted and enter localhost:3030 for your local version of the webapp, and then when asked use the API key you copied earlier.

Once that's done, you should be able to run:

pnpm exec trigger-cli dev

And because you aren't yet running your newly created Next.js server locally, then the code you added should log and exit out the dev command.

Then you should actually run the Next.js server locally, and try the dev command again and make sure it works.

@ericallam

Copy link
Copy Markdown
Member

Also, it would be amazing to get the above instructions added to the CONTRIBUTING.md guide under a section towards the end called something like "Testing CLI changes". If you can do this afterwards in a separate PR I'll definitely tip you handsomely 👍

@ericallam

Copy link
Copy Markdown
Member

Oh, and don't forget to cleanup and delete that temporary Next.js project before committing anything

@Ashutosh-Bhadauriya Ashutosh-Bhadauriya changed the title [WIP]Feat: Detect if a Next.js project is running on the specified port before opening a tunnel Feat: Detect if a Next.js project is running on the specified port before opening a tunnel Jul 25, 2023
@Ashutosh-Bhadauriya

Copy link
Copy Markdown
Contributor Author

Okay great! Will also add to CONTRIBUTING.md in the next pr 👍

@Ashutosh-Bhadauriya

Copy link
Copy Markdown
Contributor Author

Tested the changes and made some changes. Working fine 👍

Next, will raise a pr adding the above things you told in CONTRIBUTING.md

@ericallam

Copy link
Copy Markdown
Member

I just realized, this might cause a race-condition when using something like the concurrently package to run both the Next.js dev server and the @trigger.dev/cli dev command at the same time, like so:

CleanShot 2023-07-26 at 14 29 55@2x

Do you think you could test for this scenario and see if the dev command ever fails?

@Ashutosh-Bhadauriya

Copy link
Copy Markdown
Contributor Author

Okay let me try that,

I have a question. How does this copy key api key thing works? I mean I tried copying and pasting it(on notepad just to test it). and realized it doesn't work. Am I missing something?
Screenshot (4)

@Ashutosh-Bhadauriya

Copy link
Copy Markdown
Contributor Author

Okay, now its working, no idea what the issue was 😅

@Ashutosh-Bhadauriya

Copy link
Copy Markdown
Contributor Author

I just realized, this might cause a race-condition when using something like the concurrently package to run both the Next.js dev server and the @trigger.dev/cli dev command at the same time, like so:

@ericallam I tried this, the dev command seems to be working fine. It didn't fail.

@ericallam

Copy link
Copy Markdown
Member

Awesome! Can you add a changeset to this PR for @trigger.dev/cli?

@Ashutosh-Bhadauriya

Copy link
Copy Markdown
Contributor Author

Just added it

@matt-aitken
matt-aitken merged commit efd5909 into triggerdotdev:main Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TRI-728] @trigger.dev/cli dev command should actually detect if a Next.js project is running on the specified port before opening a tunnel

3 participants