Skip to content
Draft
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
13 changes: 13 additions & 0 deletions src/build/virtual/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function app(nitro: Nitro) {
const hasPlugins = nitro.options.plugins.length > 0;
const hasHooks = nitro.options.features?.runtimeHooks ?? hasPlugins;
const hasAsyncContext = !!nitro.options.experimental.asyncContext;
const runtimeBaseUrl = nitro.options.features.runtimeBaseURL;

const routingImports = [
hasRoutes && "findRoute",
Expand Down Expand Up @@ -90,6 +91,18 @@ export default function app(nitro: Nitro) {
` };`
);

if (runtimeBaseUrl) {
imports.push(`import { requestWithBaseURL } from "h3";`);
code.push(
``,
` const baseUrl = process.env.NITRO_APP_BASE_URL ?? "";`,
` const baseHandler = appHandler;`,
` appHandler = (req) => {`,
` return baseHandler(requestWithBaseURL(req, baseUrl));`,
` };`
);
}

if (hasAsyncContext) {
imports.push(`import { nitroAsyncContext } from "#nitro/runtime/context";`);
code.push(
Expand Down
5 changes: 5 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ export interface NitroOptions extends PresetOptions {
* Enable WebSocket support.
*/
websocket?: boolean;

/**
* Enable NITRO_APP_BASE_URL env var to take effect at runtime
*/
runtimeBaseURL?: boolean;
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface NitroImportMeta {
_asyncContext?: boolean;
_tasks?: boolean;
_websocket?: boolean;
_runtimeBaseURL?: boolean;
}

declare global {
Expand Down