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

fix(mw): Pass matched params in invokeOptions in runFeServer #10571

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/vite/src/runFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type { HTTPMethod } from 'find-my-way'
import { createProxyMiddleware } from 'http-proxy-middleware'
import type { Manifest as ViteBuildManifest } from 'vite'

import type { RWRouteManifestItem } from '@redwoodjs/internal/dist/routes'
import { getConfig, getPaths } from '@redwoodjs/project-config'

import { registerFwGlobalsAndShims } from './lib/registerFwGlobalsAndShims.js'
Expand Down Expand Up @@ -91,18 +90,19 @@ export async function runFeServer() {
// @MARK: In prod, we create it once up front!
const middlewareRouter = await createMiddlewareRouter()

const handleWithMiddleware = (route?: RWRouteManifestItem) => {
const handleWithMiddleware = () => {
return createServerAdapter(async (req: Request) => {
const middleware = middlewareRouter.find(
req.method as HTTPMethod,
req.url,
)?.handler as Middleware | undefined
const matchedMw = middlewareRouter.find(req.method as HTTPMethod, req.url)

if (!middleware) {
const handler = matchedMw?.handler as Middleware | undefined

if (!matchedMw) {
return new Response('No middleware found', { status: 404 })
}

const [mwRes] = await invoke(req, middleware, route ? { route } : {})
const [mwRes] = await invoke(req, handler, {
params: matchedMw?.params,
})

return mwRes.toResponse()
})
Expand Down
Loading