This repository has been archived by the owner on May 15, 2024. It is now read-only.
generated from nuxt-contrib/vue3-ssr-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from k99k5/main
Beta 0.3
- Loading branch information
Showing
4 changed files
with
42 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import path from 'node:path'; | ||
import {render} from '@/entry-server.js'; | ||
import template from './dist/client/index.html?raw'; | ||
import manifest from './dist/client/.vite/ssr-manifest.json?raw'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
const assets = express.static(path.join('./../client')); | ||
app.use('/', async (req, res, next) => { | ||
if (req.url.endsWith('/')) { | ||
return next(); | ||
} | ||
return assets(req, res, next); | ||
}); | ||
|
||
app.get('*', async (req, res) => { | ||
try { | ||
const renderRes = await render(req.originalUrl, manifest, { | ||
cookies: req.headers.cookie, | ||
}); | ||
res.status(200).send( | ||
template | ||
.replace(`<!--app-html-->`, renderRes.html) | ||
.replace(`<!--preload-links-->`, renderRes.preloadLinks) | ||
.replace(`<!--head-tags-->`, renderRes.headTags) | ||
.replace(`null;//'<!--ssr-state-->'`, renderRes.state), | ||
); | ||
} catch (e) { | ||
res.status(500).send(e.stack); | ||
} | ||
}); | ||
|
||
app.listen(3000, () => { | ||
console.log('http://localhost:3000'); | ||
}) |
This file was deleted.
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