Skip to content

Commit c79ff93

Browse files
only inherit base if not a full url
apply the same to nitro-vite2-plugin
1 parent 83733a1 commit c79ff93

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

packages/nitro-v2-vite-plugin/src/index.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { build, copyPublicAssets, createNitro, prepare } from 'nitropack'
22
import { dirname, resolve } from 'pathe'
33

4-
import type { PluginOption, Rollup } from 'vite'
4+
import type { PluginOption, ResolvedConfig, Rollup } from 'vite'
55
import type { NitroConfig } from 'nitropack'
66

77
let ssrBundle: Rollup.OutputBundle
88
let ssrEntryFile: string
99

10+
function isFullUrl(str: string): boolean {
11+
try {
12+
new URL(str)
13+
return true
14+
} catch {
15+
return false
16+
}
17+
}
18+
1019
export function nitroV2Plugin(nitroConfig?: NitroConfig): Array<PluginOption> {
20+
let resolvedConfig: ResolvedConfig
1121
return [
1222
{
1323
name: 'tanstack-nitro-v2-vite-plugin',
@@ -42,7 +52,10 @@ export function nitroV2Plugin(nitroConfig?: NitroConfig): Array<PluginOption> {
4252
},
4353
},
4454

45-
async config(_, env) {
55+
configResolved(config) {
56+
resolvedConfig = config
57+
},
58+
config(_, env) {
4659
if (env.command !== 'build') {
4760
return
4861
}
@@ -81,15 +94,18 @@ export function nitroV2Plugin(nitroConfig?: NitroConfig): Array<PluginOption> {
8194
await builder.build(server)
8295

8396
const virtualEntry = '#tanstack/start/entry'
97+
const baseURL = !isFullUrl(resolvedConfig.base)
98+
? resolvedConfig.base
99+
: undefined
84100
const config: NitroConfig = {
85-
...nitroConfig,
101+
baseURL,
86102
publicAssets: [
87103
{
88104
dir: client.config.build.outDir,
89-
baseURL: '/',
90105
maxAge: 31536000, // 1 year
91106
},
92107
],
108+
...nitroConfig,
93109
renderer: virtualEntry,
94110
rollupConfig: {
95111
...nitroConfig?.rollupConfig,

packages/start-plugin-core/src/plugin.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ export type GetConfigFn = () => {
4848
startConfig: TanStackStartOutputConfig
4949
resolvedStartConfig: ResolvedStartConfig
5050
}
51+
52+
function isFullUrl(str: string): boolean {
53+
try {
54+
new URL(str)
55+
return true
56+
} catch {
57+
return false
58+
}
59+
}
60+
5161
export function TanStackStartVitePluginCore(
5262
corePluginOpts: TanStackStartVitePluginCoreOptions,
5363
startPluginOpts: TanStackStartInputConfig,
@@ -98,12 +108,13 @@ export function TanStackStartVitePluginCore(
98108

99109
const { startConfig } = getConfig()
100110
if (startConfig.router.basepath === undefined) {
101-
startConfig.router.basepath = resolvedStartConfig.viteAppBase
111+
if (!isFullUrl(resolvedStartConfig.viteAppBase)) {
112+
startConfig.router.basepath =
113+
resolvedStartConfig.viteAppBase.replace(/^\/|\/$/g, '')
114+
} else {
115+
startConfig.router.basepath = '/'
116+
}
102117
}
103-
startConfig.router.basepath = startConfig.router.basepath.replace(
104-
/^\/|\/$/g,
105-
'',
106-
)
107118

108119
const TSS_SERVER_FN_BASE = joinPaths([
109120
'/',

0 commit comments

Comments
 (0)