Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #56 from k99k5/main
Browse files Browse the repository at this point in the history
Beta 0.3
  • Loading branch information
k99k5 committed Feb 24, 2024
2 parents b94047b + c72ce19 commit 20ff553
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dev": "node server.js",
"build": "pnpm run build:client && pnpm run build:server",
"build:client": "vite build --outDir dist/client --ssrManifest",
"build:server": "vite build --outDir dist/server --ssr src/worker.js"
"build:server": "vite build --outDir dist/server --ssr server-production.js"
},
"dependencies": {
"@duannx/vue-client-only": "^1.0.3",
Expand Down
36 changes: 36 additions & 0 deletions server-production.js
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');
})
37 changes: 0 additions & 37 deletions src/worker.js

This file was deleted.

6 changes: 5 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default defineConfig({
VitePWA({
registerType: 'autoUpdate',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
globPatterns: ['**/*.{js,css,ico,png,svg,ttf,woff,woff2,json,webp}'],
navigateFallbackDenylist: [
/^\/api/,
/^\/cdn-cgi/,
Expand Down Expand Up @@ -139,4 +139,8 @@ export default defineConfig({
define: {
__APP_VERSION: `${new Date().getFullYear()}${new Date().getMonth()}${new Date().getDate()}.${new Date().getHours()}`,
},
ssr: {
external: true,
noExternal: ['primevue'],
},
});

0 comments on commit 20ff553

Please sign in to comment.