Skip to content

Commit

Permalink
refactor(start): expose vinxi router middleware (#2893)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
  • Loading branch information
jadedevin13 and SeanCassiere authored Dec 3, 2024
1 parent c7403a3 commit 201ce5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/start/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ export function defineConfig(

const tsrConfig = getConfig(tsr)

const publicDir = opts.routers?.public?.dir || './public'

const publicBase = opts.routers?.public?.base || '/'
const clientBase = opts.routers?.client?.base || '/_build'
const serverBase = opts.routers?.server?.base || '/_server'
const apiBase = opts.tsr?.apiBase || '/api'
const serverBase = opts.routers?.server?.base || '/_server'

const apiMiddleware = opts.routers?.api?.middleware || undefined
const serverMiddleware = opts.routers?.server?.middleware || undefined
const ssrMiddleware = opts.routers?.ssr?.middleware || undefined

const clientEntry =
opts.routers?.client?.entry || path.join(appDirectory, 'client.tsx')
Expand All @@ -116,9 +123,6 @@ export function defineConfig(

const apiEntryExists = existsSync(apiEntry)

const publicDir = opts.routers?.public?.dir || './public'
const publicBase = opts.routers?.public?.base || '/'

let vinxiApp = createApp({
server: {
...serverOptions,
Expand Down Expand Up @@ -187,6 +191,7 @@ export function defineConfig(
type: 'http',
target: 'server',
handler: ssrEntry,
middleware: ssrMiddleware,
plugins: () => {
const viteConfig = getUserViteConfig(opts.vite)
const ssrViteConfig = getUserViteConfig(opts.routers?.ssr?.vite)
Expand Down Expand Up @@ -232,6 +237,7 @@ export function defineConfig(
type: 'http',
target: 'server',
base: serverBase,
middleware: serverMiddleware,
// TODO: RSCS - enable this
// worker: true,
handler: importToProjectRelative('@tanstack/start/server-handler'),
Expand Down Expand Up @@ -288,6 +294,7 @@ export function defineConfig(
target: 'server',
base: apiBase,
handler: apiEntry,
middleware: apiMiddleware,
routes: tanstackStartVinxiFileRouter({ tsrConfig, apiBase }),
plugins: () => {
const viteConfig = getUserViteConfig(opts.vite)
Expand Down
3 changes: 3 additions & 0 deletions packages/start/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const routersSchema = z.object({
ssr: z
.object({
entry: z.string().optional(),
middleware: z.string().optional(),
vite: viteSchema.optional(),
})
.optional(),
Expand All @@ -163,12 +164,14 @@ const routersSchema = z.object({
server: z
.object({
base: z.string().optional(),
middleware: z.string().optional(),
vite: viteSchema.optional(),
})
.optional(),
api: z
.object({
entry: z.string().optional(),
middleware: z.string().optional(),
vite: viteSchema.optional(),
})
.optional(),
Expand Down

0 comments on commit 201ce5b

Please sign in to comment.