fix(ssr): embed Ziggy routes as fallback for SSR context
ZiggyVue needs routes in its config, but page.props.ziggy from the server may not carry them in the SSR worker. Importing the static Ziggy config ensures routes are always available.
This commit is contained in:
+5
-6
@@ -4,6 +4,7 @@ import createServer from '@inertiajs/vue3/server'
|
||||
import { renderToString } from '@vue/server-renderer'
|
||||
import { createSSRApp, h } from 'vue'
|
||||
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
|
||||
import { Ziggy } from './ziggy';
|
||||
import { createSsrErrorHandler, logSsrError } from './ssr/errorHandler.js';
|
||||
|
||||
createServer(page =>
|
||||
@@ -24,15 +25,13 @@ createServer(page =>
|
||||
ssrApp.config.warnHandler = () => null;
|
||||
|
||||
const ziggyConfig = {
|
||||
...Ziggy,
|
||||
...page.props.ziggy,
|
||||
location: page.props.ziggy?.location
|
||||
? new URL(page.props.ziggy.location)
|
||||
: new URL(process.env.APP_URL || 'http://localhost'),
|
||||
};
|
||||
|
||||
if (page.props.ziggy?.location) {
|
||||
ziggyConfig.location = new URL(page.props.ziggy.location);
|
||||
} else {
|
||||
ziggyConfig.location = new URL(process.env.APP_URL || 'http://localhost');
|
||||
}
|
||||
|
||||
return ssrApp
|
||||
.use(plugin)
|
||||
.use(ZiggyVue, ziggyConfig);
|
||||
|
||||
Reference in New Issue
Block a user