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

Add --api Flag to Create Headless API App with create-next-app #68130

Open
wants to merge 55 commits into
base: canary
Choose a base branch
from

Conversation

Arindam200
Copy link
Contributor

@Arindam200 Arindam200 commented Jul 24, 2024

What?

Added a new option for create-next-app to create a headless API app. This includes:

  • Adding a --api flag for create-next-app to create a headless app.
  • Modifying the template to include only the required assets (no public/, app/page.*, etc.).
  • Ensuring the app includes only the required dependencies (no @types/react, react, etc.).

Why?

This feature allows users to initialize projects with headless API templates, making it easier to set up projects that require backend functionality without frontend components.

How?

  • Added the --api flag to the create-next-app command.
  • Modified the template to exclude unnecessary assets and dependencies.
  • Included exemplary usage of route.js features with comments for user guidance.
  • Implemented HTTP Methods and Parameters for request validation.

Closes #68118
Closes NEXT-3633
Closes NDX-120

Signed-off-by: Arindam Majumder <arindammajumder2020@gmail.com>
@ijjk ijjk added the create-next-app Related to our CLI tool for quickly starting a new Next.js application. label Jul 24, 2024
@Arindam200 Arindam200 changed the title add: headless-api Add --api Flag to Create Headless API App with create-next-app Jul 24, 2024
@ijjk
Copy link
Member

ijjk commented Jul 24, 2024

Allow CI Workflow Run

  • approve CI run for commit: 513d424

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@ijjk
Copy link
Member

ijjk commented Jul 24, 2024

Allow CI Workflow Run

  • approve CI run for commit: cc203c2

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Co-authored-by: Mert Can Altin <mertgold60@gmail.com>
Copy link
Member

@devjiwonchoi devjiwonchoi left a comment

Choose a reason for hiding this comment

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

Let's add a few tests at test/integration/create-next-app.

packages/create-next-app/create-app.ts Outdated Show resolved Hide resolved
packages/create-next-app/create-app.ts Outdated Show resolved Hide resolved
packages/create-next-app/create-app.ts Outdated Show resolved Hide resolved
packages/create-next-app/index.ts Outdated Show resolved Hide resolved
packages/create-next-app/templates/api/js/api/index.js Outdated Show resolved Hide resolved
packages/create-next-app/templates/types.ts Outdated Show resolved Hide resolved
packages/create-next-app/templates/types.ts Outdated Show resolved Hide resolved
Arindam200 and others added 3 commits July 27, 2024 02:20
Co-authored-by: Jiwon Choi <devjiwonchoi@gmail.com>
Co-authored-by: Jiwon Choi <devjiwonchoi@gmail.com>
Co-authored-by: Jiwon Choi <devjiwonchoi@gmail.com>
@ephraimduncan
Copy link
Contributor

I tried pushing to this but looks like I don't have access. @Arindam200

@Arindam200
Copy link
Contributor Author

Sure, I'm giving you the access

@Arindam200
Copy link
Contributor Author

I tried pushing to this but looks like I don't have access. @Arindam200

I've invited you, can you please accept that?

.husky/next.config.ts Outdated Show resolved Hide resolved
packages/create-next-app/index.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,3 @@
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
MY_HOST="example.com"
Copy link
Member

Choose a reason for hiding this comment

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

We can likely remove this

Copy link
Member

Choose a reason for hiding this comment

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

The other templates also share this file, should we still remove it?
x-ref: https://github.com/vercel/next.js/blob/canary/packages/create-next-app/templates/app/ts/.env.example

packages/create-next-app/templates/api/js/eslintrc.json Outdated Show resolved Hide resolved
packages/create-next-app/templates/api/js/next.config.mjs Outdated Show resolved Hide resolved
packages/create-next-app/create-app.ts Outdated Show resolved Hide resolved
packages/create-next-app/create-app.ts Outdated Show resolved Hide resolved
devjiwonchoi and others added 2 commits July 30, 2024 13:55
Co-authored-by: Ahmed Abdelbaset <A7med3bdulBaset@gmail.com>
@0xgitx0
Copy link

0xgitx0 commented Aug 5, 2024

@devjiwonchoi Hi, I added some ts examples, please take time to review, thanks!

@devjiwonchoi
Copy link
Member

@Tim-Zj Wow, great work! Will take time to review. Thank you!

@devjiwonchoi
Copy link
Member

@Arindam200 Would you like to take a look at the changes?

@samcx samcx self-requested a review August 15, 2024 21:28
Copy link
Member

@samcx samcx left a comment

Choose a reason for hiding this comment

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

:lfgtm:

@Arindam200
Copy link
Contributor Author

Arindam200 commented Aug 16, 2024

@Arindam200 Would you like to take a look at the changes?

Sure. I've added some query/feedbacks @devjiwonchoi .

Copy link

@sujii sujii left a comment

Choose a reason for hiding this comment

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

Awesome!

# Rename this file to `.env.local` to use environment variables locally with `next dev`
# Add .env files to your .gitignore to prevent accidentally committing sensitive information.
# https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
MY_HOST="example.com"
Copy link
Member

Choose a reason for hiding this comment

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

Is this used?

Copy link
Member

@huozhi huozhi left a comment

Choose a reason for hiding this comment

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

Some feedbacks on the template @devjiwonchoi

  • Can we have some tests on Next.js side first to make sure it works in dev and build mode first?
  • When I look [...not-found]/route.js should not be required, and it's not working as expected when I test against the generated route
  • with-middleware.js looks a bit confused to me when there's no middleware.js but also need to be applied for each route.
  • Can we merge the dynamic routes cases between the pokemon/[number] and methods/[method]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option for create-next-app to create a headless API app.