question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The what and why of wrapping a NextJS client with `@keystone-alpha/app-next`.

See original GitHub issue

The Custom Server section of the KS5 docs mention @keystone-alpha/app-next for serving a Next.js App on the same server as the API.

What attracted me to this was simplifying my app by maintaining a single NodeJS server.

  • Why else would I want to do this?
  • What would I gain or lose from doing this?

I’m happy to be pointed to any insightful resources.

I tried digging around the source code and found that app-next provides a wrapper for Keystone app.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
jesstelfordcommented, Aug 13, 2019

Great question!

The entire app-* ecosystem within KeystoneJS is based around the idea of deploying everything to a single server.

This is by far not the only way to deploy things, and so comes with some trade-offs:

Pros

  • Very simple getting started - setup the app and everything will “Just work”
  • Is opt-in with low barrier to entry
  • Provides extension points for adding different kinds of apps in the future

Cons

  • Your frontend (next.js) and API (Keystone) cannot scale independently
  • Depending on the app, your frontend and api code will be executed within the same node.js thread. Ie; server-side rendering in the next.js app will block API requests.
  • While it’s technically possible to deploy to a serverless environment like this, it’s not trivial and reaps almost none of the rewards of serverless
  • Side-steps optimisations you may want to take advantage of. ie; in the app-static app, there’s no way to deploy your static assets to a globally cached CDN.

You should only use apps (other than the graphql app) when you’re comfortable with the above trade-offs. If you grow beyond that, you can eject out of the app ecosystem and setup your own hosting and deployment pipeline to reap the benefits you desire.

3reactions
jesstelfordcommented, Mar 2, 2020

Yes you’re right - they’d still be within the same node process. The next-app is just a thin wrapper over doing a custom server.

It sounds like you want to keep your Next & Keystone apps running independently; they’d have their own "start" commands, be deployed separately, have their own logging and monitoring, etc.

For example, you might deploy your Keystone app to https://api.example.com, then in your Next app set up the GraphQL client to have uri: "https://api.example.com", and be deployed to https://www.example.com

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Custom `App` - Next.js
Control page initialization and add a layout that persists for all pages by overriding the default App component used by Next.js.
Read more >
@keystonejs/app-next - npm
Start using @keystonejs/app-next in your project by running `npm i ... A KeystoneJS app for serving a Next.js application.
Read more >
What's New in Next.js 13 - AppSignal Blog
Let's explore the new features and improvements in Next.js 13. ... Additional JavaScript will only be added as client-side interactivity is ...
Read more >
Next.js 13: Working with the new app directory - LogRocket Blog
tsx is an optional file that you can create within any directory inside the app folder. It automatically wraps the page inside of...
Read more >
What's new in Next.js 13, and what do they really do?
jsx be a Server Component that wraps your client provider…that wraps children/UI in turn. 3. Your favorite UI Library might not work. Server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found