-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
10 changed files
with
61 additions
and
166 deletions.
There are no files selected for viewing
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,28 @@ | ||
import type { Plugin } from 'vite' | ||
import { readableToString } from './serverUtils' | ||
|
||
interface PluginConfig { | ||
renderer: string | ||
} | ||
|
||
export default function inertia(config: PluginConfig): Plugin { | ||
// todo: validate config | ||
|
||
return { | ||
name: '@inertiajs/svelte/ssr', | ||
async configureServer(server) { | ||
return () => | ||
server.middlewares.use(async (req, res, next) => { | ||
if (req.url !== '/render') { | ||
next() | ||
} | ||
|
||
// todo: check if render is a function | ||
const { render } = await server.ssrLoadModule(config.renderer) | ||
const response = await render(JSON.parse(await readableToString(req))) | ||
res.writeHead(200, { 'Content-Type': 'application/json' }) | ||
res.end(JSON.stringify(response)) | ||
}) | ||
}, | ||
} | ||
} |
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
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,8 @@ | ||
import { createInertiaApp } from '@inertiajs/svelte' | ||
import type { AppCallback } from '@inertiajs/svelte/server' | ||
|
||
export const render: AppCallback = (page) => | ||
createInertiaApp({ | ||
page, | ||
resolve: (name) => import(`./Pages/${name}.svelte`), | ||
}) |
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