-
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
4,021 additions
and
5,860 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { IncomingMessage } from 'http' | ||
|
||
export const readableToString: (readable: IncomingMessage) => Promise<string> = (readable) => | ||
new Promise((resolve, reject) => { | ||
let data = '' | ||
readable.on('data', (chunk) => (data += chunk)) | ||
readable.on('end', () => resolve(data)) | ||
readable.on('error', (err) => reject(err)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Plugin } from 'vite' | ||
import { readableToString } from './serverUtils' | ||
|
||
interface PluginConfig { | ||
renderer: string | ||
} | ||
|
||
export default function inertia(config: string | PluginConfig): Plugin { | ||
const resolvedConfig = resolveConfig(config) | ||
|
||
return { | ||
name: '@inertiajs/core/vite', | ||
async configureServer(server) { | ||
return () => | ||
server.middlewares.use(async (req, res, next) => { | ||
if (req.url !== '/render') { | ||
next() | ||
} | ||
|
||
const { default: render } = await server.ssrLoadModule(resolvedConfig.renderer) | ||
const response = await render(JSON.parse(await readableToString(req))) | ||
res.writeHead(200, { 'Content-Type': 'application/json' }) | ||
res.end(JSON.stringify(response)) | ||
}) | ||
}, | ||
} | ||
} | ||
|
||
function resolveConfig(config: string | PluginConfig) { | ||
if (typeof config === 'undefined') { | ||
throw new Error('@inertiajs/core/vite: missing configuration.') | ||
} | ||
|
||
if (typeof config === 'string') { | ||
return { renderer: config } | ||
} | ||
|
||
if (typeof config.renderer === 'undefined') { | ||
throw new Error('@inertiajs/core/vite: missing configuration for "renderer".') | ||
} | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from '@inertiajs/core/server' | ||
export { default as default } from '@inertiajs/core/server' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from '@inertiajs/core/server' | ||
export { default as default } from '@inertiajs/core/server' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from '@inertiajs/core/server' | ||
export { default as default } from '@inertiajs/core/server' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { createInertiaApp } from '@inertiajs/react' | ||
import type { AppCallback } from '@inertiajs/react/server' | ||
import * as ReactDOMServer from 'react-dom/server' | ||
|
||
const render: AppCallback = (page) => | ||
createInertiaApp({ | ||
page, | ||
render: ReactDOMServer.renderToString, | ||
title: (title) => `${title} - React Playground`, | ||
resolve: (name) => import(`./Pages/${name}.tsx`), | ||
setup: ({ App, props }) => <App {...props} />, | ||
}) | ||
|
||
export default render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createInertiaApp } from '@inertiajs/svelte' | ||
import type { AppCallback } from '@inertiajs/svelte/server' | ||
|
||
const render: AppCallback = (page) => | ||
createInertiaApp({ | ||
page, | ||
resolve: (name) => import(`./Pages/${name}.svelte`), | ||
}) | ||
|
||
export default render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createInertiaApp } from '@inertiajs/svelte' | ||
import type { AppCallback } from '@inertiajs/svelte/server' | ||
|
||
const render: AppCallback = (page) => | ||
createInertiaApp({ | ||
page, | ||
resolve: (name) => import(`./Pages/${name}.svelte`), | ||
}) | ||
|
||
export default render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createInertiaApp } from '@inertiajs/vue3' | ||
import type { AppCallback } from '@inertiajs/vue3/server' | ||
import { renderToString } from '@vue/server-renderer' | ||
import { createSSRApp, h } from 'vue' | ||
|
||
const render: AppCallback = (page) => | ||
createInertiaApp({ | ||
page, | ||
render: renderToString, | ||
title: (title) => `${title} - Vue 3 Playground`, | ||
resolve: (name) => import(`./Pages/${name}.vue`), | ||
setup({ App, props, plugin }) { | ||
return createSSRApp({ | ||
render: () => h(App, props), | ||
}).use(plugin) | ||
}, | ||
}) | ||
|
||
export default render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters