sveltejs / sveltejs/kit

Support multiple builds at the same time with Node.js adapter

Open
#14,975 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pkg:adapter-node
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

I have two projects: one provides auth and admin functionality with routes at /login, /register, etc., and the other provides an app using this auth including new routes. Both projects' svelte components and routes are compiled independently, with the intent to run them at the same time. The app/plugin (of which multiple can co-exist) can be swapped out in between different invocations/runs/instances of the server.

Unfortunatly, it appears that either Sveltekit or the Node.js adapter has no way to "fallthrough" to other code. Once a request is given to the adapter's handler, it will be responded too even when the handler doesn't have the page. While this makes sense when having a single handler, it fails when having two handlers.

For example, this is similar to my use case:

import { createServer } from 'node:http';
import { handler as mainHandler } from './path/to/main/handler.js';
import { plugins } from 'example/plugins';

const handlers = [mainHandler];

for (const plugin of plugins) {
	handlers.push(await import(plugin.handlerPath));
}

createServer((req, res) => {
	for (const handler of handlers) {
		function next(err) {
			// ... handles going to the next sveltekit handler
		}

		handler(req, res, next);
	}
});
Describe the proposed solution

A boolean option (e.g. fallthrough) that controls whether Sveltekit's Node.js adapter falls through (e.g. calling next() ) or not would fix the problem.

Alternatives considered

I've spent hours trying to work around the problem by attempting to isolate Sveltekit, however this failed.

The only way I've found to fix the issue is to compile in production.

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Node.js adapter handler described in the issue and trace how it responds when a route is missing. Reproduce the case with two independently built handlers using the provided node:http pattern, then verify that the configured behavior reaches the next handler without breaking the default single-handler behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.