-
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reproduce wrong early hints for HTML-only (#1574)
- Loading branch information
Showing
6 changed files
with
86 additions
and
14 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
examples/render-modes/.test-preview.test.ts → examples/render-modes/.test-prod.test.ts
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,2 +1,2 @@ | ||
import { testRun } from './.testRun' | ||
testRun('npm run preview', true) | ||
testRun('npm run prod', true) |
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,54 @@ | ||
// This file isn't processed by Vite, see https://github.com/vikejs/vike/issues/562 | ||
// Consequently: | ||
// - When changing this file, you needed to manually restart your server for your changes to take effect. | ||
// - To use your environment variables defined in your .env files, you need to install dotenv, see https://vike.dev/env | ||
// - To use your path aliases defined in your vite.config.js, you need to tell Node.js about them, see https://vike.dev/path-aliases | ||
|
||
import express from 'express' | ||
import compression from 'compression' | ||
import { renderPage } from 'vike/server' | ||
import { root } from './root.js' | ||
const isProduction = process.env.NODE_ENV === 'production' | ||
|
||
startServer() | ||
|
||
async function startServer() { | ||
const app = express() | ||
|
||
app.use(compression()) | ||
|
||
if (isProduction) { | ||
const sirv = (await import('sirv')).default | ||
app.use(sirv(`${root}/dist/client`)) | ||
} else { | ||
const vite = await import('vite') | ||
const viteDevMiddleware = ( | ||
await vite.createServer({ | ||
root, | ||
server: { middlewareMode: true } | ||
}) | ||
).middlewares | ||
app.use(viteDevMiddleware) | ||
} | ||
|
||
app.get('*', async (req, res, next) => { | ||
const pageContextInit = { | ||
urlOriginal: req.originalUrl | ||
} | ||
const pageContext = await renderPage(pageContextInit) | ||
const { httpResponse } = pageContext | ||
if (!httpResponse) { | ||
return next() | ||
} else { | ||
const { statusCode, headers, earlyHints } = httpResponse | ||
if (res.writeEarlyHints) res.writeEarlyHints({ link: earlyHints.map((e) => e.earlyHintLink) }) | ||
headers.forEach(([name, value]) => res.setHeader(name, value)) | ||
res.status(statusCode) | ||
httpResponse.pipe(res) | ||
} | ||
}) | ||
|
||
const port = process.env.PORT || 3000 | ||
app.listen(port) | ||
console.log(`Server running at http://localhost:${port}`) | ||
} |
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 @@ | ||
export { root } | ||
|
||
// https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-when-using-the-experimental-modules-flag/50052194#50052194 | ||
|
||
import { dirname } from 'path' | ||
import { fileURLToPath } from 'url' | ||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
const root = `${__dirname}/..` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.