RFC: Custom _server.ts setup file #45628
Replies: 11 comments 6 replies
-
+1 on this one! I'm unable to use |
Beta Was this translation helpful? Give feedback.
-
I refresh this repository weekly in the hopes that this RFC gets noticed. |
Beta Was this translation helpful? Give feedback.
-
Implementation 1It seems more flexible |
Beta Was this translation helpful? Give feedback.
-
+100 Implementation 1 |
Beta Was this translation helpful? Give feedback.
-
+100, this is sorely needed |
Beta Was this translation helpful? Give feedback.
-
we really need this! |
Beta Was this translation helpful? Give feedback.
-
+100 really need |
Beta Was this translation helpful? Give feedback.
-
I voted for this earlier, but just to make sure. I want to know if this RFC will provide a way for me to do what I want. I would like to call |
Beta Was this translation helpful? Give feedback.
-
I'd like this to do some configuration validation so I can spit out user-friendly errors and exit the process before the configuration becomes a problem or spits out unfriendly errors. |
Beta Was this translation helpful? Give feedback.
-
It's a nice proposal, but respectfully, I don't think it clearly articulates why the status-quo is not acceptable. Next.js offer It's actually quite wonderful. do whatever you want, then load next.js. Next.js turns into a library, vs a top-level executable, which is exactly what you want, because you want to do custom stuff. This proposal has the real con of putting next.js in front of all of the customization you may want to apply before it. For instance, I launch multiple next servers (middlewares, really), from my custom server implementation. This proposal would break that awesome capability. What's being asked here IMHO is for a redundant API with less-capable utility. I think next.js team hit the sweet spot:
just my 2c |
Beta Was this translation helpful? Give feedback.
-
I just realized I haven't commented back here: we have a solution for this now! https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation // instrumentation.ts
import { init } from 'package-init'
export function register() {
init()
} Let me know if this solves your use case. |
Beta Was this translation helpful? Give feedback.
-
Background / Motivation
https://jake.tl/notes/2021-04-04-nextjs-preload-hack
#16600
Currently, if you want to insert some custom code either before or after the nextJS server starts up, you're faced with 2 options:
node_modules/.bin/next start
I, myself, am currently planning to add some datadog APM stuff to my set up, and this is why I'm interested in something like this. I can also imagine other use cases:
Idea
NextJS already has concepts like
_app.tsx
and_document.tsx
for customizing the app and document respectively. Other abstractions also, exist, like404.tsx
and500.tsx
. In similar fashion, addingpages/_server.ts
would be treated as a special file, whose default export is an async function that can be used to execute custom code before and after the nextJS server starts. In the example, I'm using typescript to show what kind of types I might expect from this feature's API.Implementation 1: a single Koa-style async function
Implementation 2: Multiple named exports
Another way this might be implemented is via named exports, but I think this makes it less flexible, particularly in the case where a post-server task depends on the result of a pre-server task. This might look something like this:
Other things
Beta Was this translation helpful? Give feedback.
All reactions