forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: prefetch modules, fix windows build
- Loading branch information
1 parent
b4def22
commit a30f18a
Showing
79 changed files
with
2,235 additions
and
1,438 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 was deleted.
Oops, something went wrong.
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
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,9 +1,34 @@ | ||
# Build | ||
build | ||
dist | ||
server | ||
functions/**/*.js | ||
|
||
# Development | ||
node_modules | ||
|
||
# Cache | ||
.cache | ||
.mf | ||
.vscode | ||
.rollup.cache | ||
server | ||
dist | ||
node_modules | ||
tsconfig.tsbuildinfo | ||
q-symbols.json | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
# Editor | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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,74 +1,5 @@ | ||
/* eslint-disable */ | ||
|
||
// @ts-ignore | ||
import { render } from '../server/entry.server.js'; | ||
import type { RenderToStringOptions, RenderToStringResult } from '@builder.io/qwik/server'; | ||
|
||
// @ts-ignore | ||
import manifest from '../dist/q-manifest.json'; | ||
|
||
export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) => { | ||
try { | ||
const url = new URL(request.url); | ||
if (url.hostname === 'qwik.builder.io' && url.pathname === '/') { | ||
// temporarily redirect homepage to the overview page | ||
return Response.redirect('https://qwik.builder.io/docs/overview', 302); | ||
} | ||
|
||
if (url.pathname === '/chat') { | ||
return Response.redirect('https://discord.gg/bNVSQmPzqy'); | ||
} | ||
|
||
// Handle static assets | ||
if (/\.\w+$/.test(url.pathname) || url.pathname === '/repl/') { | ||
return next(request); | ||
} | ||
|
||
// do not using caching during development | ||
const useCache = url.hostname !== 'localhost'; | ||
|
||
// Early return from cache | ||
const cache = await caches.open('custom:qwik'); | ||
if (useCache) { | ||
const cachedResponse = await cache.match(request); | ||
if (cachedResponse) { | ||
return cachedResponse; | ||
} | ||
} | ||
|
||
// Render To String Options | ||
const opts: RenderToStringOptions = { | ||
url: request.url, | ||
base: '/build/', | ||
manifest: manifest as any, | ||
prefetchStrategy: { | ||
symbolsToPrefetch: 'events-document', | ||
implementation: 'link-prefetch', | ||
}, | ||
}; | ||
|
||
// Generate Qwik SSR response | ||
const result: RenderToStringResult = await render(opts); | ||
|
||
const response = new Response(result.html, { | ||
headers: { | ||
'Cross-Origin-Embedder-Policy': 'credentialless', | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
'Content-Type': 'text/html; charset=utf-8', | ||
'Cache-Control': useCache | ||
? `max-age=60, s-maxage=10, stale-while-revalidate=604800, stale-if-error=604800` | ||
: `no-cache, max-age=0`, | ||
}, | ||
}); | ||
|
||
if (useCache) { | ||
waitUntil(cache.put(request, response.clone())); | ||
} | ||
|
||
// Return Qwik SSR response | ||
return response; | ||
} catch (e: any) { | ||
// 500 Error | ||
return new Response(String(e.stack || e), { status: 500 }); | ||
} | ||
}; | ||
// Cloudflare Pages Functions | ||
// https://developers.cloudflare.com/pages/platform/functions/ | ||
export { onRequestGet } from '../server/entry.cloudflare.js'; |
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,62 @@ | ||
import { render } from './entry.ssr'; | ||
|
||
export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) => { | ||
try { | ||
const url = new URL(request.url); | ||
if (url.hostname === 'qwik.builder.io' && url.pathname === '/') { | ||
// temporarily redirect homepage to the overview page | ||
return Response.redirect('https://qwik.builder.io/docs/overview', 302); | ||
} | ||
|
||
if (url.pathname === '/chat') { | ||
return Response.redirect('https://discord.gg/bNVSQmPzqy'); | ||
} | ||
|
||
// Handle static assets | ||
if (/\.\w+$/.test(url.pathname) || url.pathname === '/repl/') { | ||
return next(request); | ||
} | ||
|
||
// do not using caching during development | ||
const useCache = url.hostname !== 'localhost'; | ||
|
||
// Early return from cache | ||
const cache = await caches.open('custom:qwik'); | ||
if (useCache) { | ||
const cachedResponse = await cache.match(request); | ||
if (cachedResponse) { | ||
return cachedResponse; | ||
} | ||
} | ||
|
||
// Generate Qwik SSR response | ||
const result = await render({ | ||
url: request.url, | ||
prefetchStrategy: { | ||
symbolsToPrefetch: 'events-document', | ||
implementation: 'link-prefetch', | ||
}, | ||
}); | ||
|
||
const response = new Response(result.html, { | ||
headers: { | ||
'Cross-Origin-Embedder-Policy': 'credentialless', | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
'Content-Type': 'text/html; charset=utf-8', | ||
'Cache-Control': useCache | ||
? `max-age=60, s-maxage=10, stale-while-revalidate=604800, stale-if-error=604800` | ||
: `no-cache, max-age=0`, | ||
}, | ||
}); | ||
|
||
if (useCache) { | ||
waitUntil(cache.put(request, response.clone())); | ||
} | ||
|
||
// Return Qwik SSR response | ||
return response; | ||
} catch (e: any) { | ||
// 500 Error | ||
return new Response(String(e.stack || e), { status: 500 }); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
6 changes: 2 additions & 4 deletions
6
...apps/starter-builder/src/entry.server.tsx → packages/docs/src/entry.ssr.tsx
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,9 +1,7 @@ | ||
import { renderToString, RenderToStringOptions } from '@builder.io/qwik/server'; | ||
// import { manifest } from '@qwik-client-manifest'; | ||
import { Root } from './root'; | ||
|
||
/** | ||
* Qwik server-side render function. | ||
*/ | ||
export function render(opts: RenderToStringOptions) { | ||
return renderToString(<Root />, opts); | ||
return renderToString(<Root />, { ...opts }); | ||
} |
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
Oops, something went wrong.