File tree Expand file tree Collapse file tree 8 files changed +20
-38
lines changed
Expand file tree Collapse file tree 8 files changed +20
-38
lines changed Original file line number Diff line number Diff line change 11import { defineNitroConfig } from "nitro/config" ;
22
33export default defineNitroConfig ( {
4- serverEntry : { format : "node" } ,
4+ routes : {
5+ "/**" : { handler : "./server" , format : "node" } ,
6+ } ,
57} ) ;
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ export function routing(nitro: Nitro) {
2828
2929 return /* js */ `
3030import * as __routeRules__ from "nitro/runtime/internal/route-rules";
31- ${ nitro . options . serverEntry ?. handler ? `import __serverEntry__ from ${ JSON . stringify ( nitro . options . serverEntry . handler ) } ;` : "" }
3231import * as srvxNode from "srvx/node"
3332import * as h3 from "h3";
3433
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ export const NitroDefaults: NitroConfig = {
5252 handlers : [ ] ,
5353 devHandlers : [ ] ,
5454 errorHandler : undefined ,
55+ routes : { } ,
5556 routeRules : { } ,
5657 prerender : {
5758 autoSubfolderIndex : true ,
Original file line number Diff line number Diff line change @@ -70,28 +70,16 @@ export async function resolvePathOptions(options: NitroOptions) {
7070 options . scanDirs = [ ...new Set ( options . scanDirs . map ( ( dir ) => dir + "/" ) ) ] ;
7171
7272 // Resolve server entry
73- if ( typeof options . serverEntry === "string" ) {
74- options . serverEntry = { handler : options . serverEntry } ;
75- }
76- if ( options . serverEntry ?. handler ) {
77- options . serverEntry . handler = resolveModulePath (
78- resolveNitroPath ( options . serverEntry . handler , options ) ,
79- {
80- from : options . scanDirs ,
81- extensions : RESOLVE_EXTENSIONS ,
82- }
83- ) ! ;
84- } else {
85- const defaultServerEntry = resolveModulePath ( "./server" , {
73+ if ( ! options . routes [ "/**" ] ?. handler ) {
74+ const serverEntry = resolveModulePath ( "./server" , {
8675 from : options . scanDirs ,
8776 extensions : RESOLVE_EXTENSIONS ,
8877 try : true ,
8978 } ) ;
90- if ( defaultServerEntry ) {
91- options . serverEntry ??= { } ;
92- options . serverEntry . handler = defaultServerEntry ;
79+ if ( serverEntry ) {
80+ options . routes [ "/**" ] = { handler : serverEntry } ;
9381 consola . info (
94- `Using \`${ prettyPath ( defaultServerEntry ) } \` as server entry .`
82+ `Using \`${ prettyPath ( serverEntry ) } \` as default route handler .`
9583 ) ;
9684 }
9785 }
Original file line number Diff line number Diff line change 1- import { defu } from "defu" ;
21import type {
32 NitroConfig ,
43 NitroOptions ,
@@ -8,9 +7,6 @@ import type {
87import { withLeadingSlash } from "ufo" ;
98
109export async function resolveRouteRulesOptions ( options : NitroOptions ) {
11- // Backward compatibility for options.routes
12- options . routeRules = defu ( options . routeRules , ( options as any ) . routes || { } ) ;
13-
1410 options . routeRules = normalizeRouteRules ( options ) ;
1511}
1612
Original file line number Diff line number Diff line change @@ -38,8 +38,6 @@ export function initNitroRouting(nitro: Nitro) {
3838 NitroEventHandler & { _importHash : string }
3939 > ( ) ;
4040
41- const warns : Set < string > = new Set ( ) ;
42-
4341 const sync = ( ) => {
4442 // Update route rules
4543 routeRules . _update (
@@ -55,16 +53,12 @@ export function initNitroRouting(nitro: Nitro) {
5553
5654 // Update routes
5755 const _routes = [
58- ...nitro . scannedHandlers ,
56+ ...Object . entries ( nitro . options . routes ) . flatMap ( ( [ route , handler ] ) => {
57+ return { ...handler , route, middleware : false } ;
58+ } ) ,
5959 ...nitro . options . handlers ,
60+ ...nitro . scannedHandlers ,
6061 ] . filter ( ( h ) => h && ! h . middleware && matchesEnv ( h ) ) ;
61- if ( nitro . options . serverEntry ?. handler ) {
62- _routes . unshift ( {
63- route : "/**" ,
64- handler : nitro . options . serverEntry . handler ,
65- format : nitro . options . serverEntry . format ,
66- } ) ;
67- }
6862 if ( nitro . options . renderer ?. entry ) {
6963 _routes . push ( {
7064 route : "/**" ,
Original file line number Diff line number Diff line change @@ -183,12 +183,16 @@ export interface NitroOptions extends PresetOptions {
183183 // Routing
184184 baseURL : string ;
185185 apiBaseURL : string ;
186- serverEntry : { handler ?: string ; format ?: EventHandlerFormat } | undefined ;
186+
187+ routes : Record < string , Omit < NitroEventHandler , "route" | "middleware" > > ;
187188 handlers : NitroEventHandler [ ] ;
188- routeRules : { [ path : string ] : NitroRouteRules } ;
189189 devHandlers : NitroDevEventHandler [ ] ;
190+
191+ routeRules : { [ path : string ] : NitroRouteRules } ;
192+
190193 errorHandler : string | string [ ] ;
191194 devErrorHandler : NitroErrorHandler ;
195+
192196 prerender : {
193197 /**
194198 * Prerender HTML routes within subfolders (`/test` would produce `/test/index.html`)
@@ -270,7 +274,6 @@ export interface NitroConfig
270274 Omit <
271275 NitroOptions ,
272276 | "routeRules"
273- | "serverEntry"
274277 | "rollupConfig"
275278 | "preset"
276279 | "compatibilityDate"
@@ -286,7 +289,6 @@ export interface NitroConfig
286289 rollupConfig ?: Partial < RollupConfig > ;
287290 compatibilityDate ?: CompatibilityDateSpec ;
288291 unenv ?: UnenvPreset | UnenvPreset [ ] ;
289- serverEntry ?: string | NitroOptions [ "serverEntry" ] ;
290292}
291293
292294// ------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ describe("minimal fixture", () => {
5151 it ( "bundle size" , async ( ) => {
5252 const { sizeKB } = await analyzeDir ( outDir ) ;
5353 const expectedSize = bundleSizes [ builder ] [ minify ? 1 : 0 ] ;
54- // expect(Math.round(sizeKB)).toBe(expectedSize);
54+ expect ( Math . round ( sizeKB ) ) . toBe ( expectedSize ) ;
5555
5656 results . push ( {
5757 builder : builder + ( minify ? " (minified)" : "" ) ,
You can’t perform that action at this time.
0 commit comments