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

refactor(start): expose vinxi router middleware #2893

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
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
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
Loading