-
Notifications
You must be signed in to change notification settings - Fork 404
Open
Labels
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
Calling proxyRequest from my middleware causes both the dev server and the production build to crash:
import { createMiddleware } from "@solidjs/start/middleware";
import { proxyRequest } from "vinxi/http";
export default createMiddleware({
onRequest: (event) => {
return proxyRequest(event.nativeEvent, "http://localhost:8080");
},
});The console shows the following error:
node:_http_outgoing:699
throw new ERR_HTTP_HEADERS_SENT('set');
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (node:_http_outgoing:699:11)
at setResponseHeader (file:///<redacted>/node_modules/h3/dist/index.mjs:799:18)
at errorHandler (file:///<redacted>/node_modules/vinxi/lib/dev-error.js:10:2)
at Object.onError (file:///<redacted>/node_modules/vinxi/lib/nitro-dev.js:159:11)
at Server.toNodeHandle (file:///<redacted>/node_modules/h3/dist/index.mjs:2303:27)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
Node.js v22.11.0
error: script "dev" exited with code 1
The above approach works when using defineMiddleware exported from vinxi:
import { defineMiddleware, proxyRequest } from "vinxi/http";
export default defineMiddleware({
onRequest: (event) => {
return proxyRequest(event, "http://localhost:8080");
},
});EDIT: What's interesting is that it works when I don't return the response from proxyRequest, but only await it.
import { createMiddleware } from "@solidjs/start/middleware";
import { proxyRequest } from "vinxi/http";
export default createMiddleware({
onRequest: async (event) => {
await proxyRequest(event.nativeEvent, "http://localhost:8080");
},
});Expected behavior 🤔
The middleware should not cause the server to crash.
Steps to reproduce 🕹
Steps:
- Create a new SolidStart project.
- Create
src/middleware.tsand paste the snippet from above. - Register the middleware in
app.config.ts:export default defineConfig({ middleware: "src/middleware.ts", });
- Run
docker run -p 8080:80 nginxdemos/hello. - Navigate to http://localhost:3000.
- The server should crash.
Context 🔦
I am attempting to write a small application that forwards HTTP requests to another Docker container if the user is authorized to do so.
Your environment 🌎
System:
OS: maxOS Sequoia 15.0.1
CPU: Apple M1 Pro
Binaries:
Node: 22.11.0 - /Users/amadeus/.nvm/versions/node/v22.11.0/bin/node
npm: 10.9.0 - /Users/amadeus/.nvm/versions/node/v22.11.0/bin/npm
Bun: 1.2.23 - /opt/homebrew/bin/bun
npmPackages:
@solidjs/start: ^1.1.0
vinxi: ^0.5.10