@@ -31,6 +31,8 @@ const __dirname = dirname(__filename);
31
31
export function nitro ( options ?: Options , nitroOptions ?: NitroConfig ) : Plugin [ ] {
32
32
const workspaceRoot = options ?. workspaceRoot ?? process . cwd ( ) ;
33
33
let isTest = process . env [ 'NODE_ENV' ] === 'test' || ! ! process . env [ 'VITEST' ] ;
34
+ const baseURL = process . env [ 'NITRO_APP_BASE_URL' ] || '' ;
35
+ const prefix = baseURL ? baseURL . substring ( 0 , baseURL . length - 1 ) : '' ;
34
36
const apiPrefix = `/${ options ?. apiPrefix || 'api' } ` ;
35
37
const useAPIMiddleware =
36
38
typeof options ?. useAPIMiddleware !== 'undefined'
@@ -122,6 +124,7 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
122
124
} ,
123
125
runtimeConfig : {
124
126
apiPrefix : apiPrefix . substring ( 1 ) ,
127
+ prefix,
125
128
} ,
126
129
rollupConfig : {
127
130
onwarn ( warning ) {
@@ -152,7 +155,7 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
152
155
: useAPIMiddleware
153
156
? undefined
154
157
: {
155
- [ `${ apiPrefix } /**` ] : {
158
+ [ `${ prefix } ${ apiPrefix } /**` ] : {
156
159
proxy : { to : '/**' } ,
157
160
} ,
158
161
} ,
@@ -164,7 +167,8 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
164
167
import { useRuntimeConfig } from '#imports';
165
168
166
169
export default eventHandler(async (event) => {
167
- const apiPrefix = \`/\${useRuntimeConfig().apiPrefix}\`;
170
+ const prefix = useRuntimeConfig().prefix;
171
+ const apiPrefix = \`\${prefix}/\${useRuntimeConfig().apiPrefix}\`;
168
172
169
173
if (event.node.req.url?.startsWith(apiPrefix)) {
170
174
const reqUrl = event.node.req.url?.replace(apiPrefix, '');
@@ -411,7 +415,7 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
411
415
if ( hasAPIDir ) {
412
416
viteServer . middlewares . use (
413
417
( req : IncomingMessage , res : ServerResponse , next : Function ) => {
414
- if ( req . url ?. startsWith ( apiPrefix ) ) {
418
+ if ( req . url ?. startsWith ( ` ${ prefix } ${ apiPrefix } ` ) ) {
415
419
apiHandler ( req , res ) ;
416
420
return ;
417
421
}
@@ -436,7 +440,7 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
436
440
}
437
441
438
442
console . log (
439
- `\n\nThe server endpoints are accessible under the "${ apiPrefix } " path.` ,
443
+ `\n\nThe server endpoints are accessible under the "${ prefix } ${ apiPrefix } " path.` ,
440
444
) ;
441
445
}
442
446
} ,
@@ -484,7 +488,7 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
484
488
config ( ) {
485
489
return {
486
490
define : {
487
- ANALOG_API_PREFIX : `"${ apiPrefix . substring ( 1 ) } "` ,
491
+ ANALOG_API_PREFIX : `"${ baseURL . substring ( 1 ) } ${ apiPrefix . substring ( 1 ) } "` ,
488
492
} ,
489
493
} ;
490
494
} ,
0 commit comments