create-qwik
Advanced tools
Comparing version 0.0.20-3 to 0.0.20-4
{ | ||
"name": "create-qwik", | ||
"version": "0.0.20-3", | ||
"version": "0.0.20-4", | ||
"description": "Interactive CLI and API for generating Qwik projects.", | ||
@@ -5,0 +5,0 @@ "bin": "create-qwik", |
@@ -8,3 +8,3 @@ { | ||
"build.client": "vite build", | ||
"build.ssr": "vite build --mode ssr", | ||
"build.ssr": "vite build --ssr src/entry.server.tsx", | ||
"dev": "vite", | ||
@@ -17,3 +17,3 @@ "dev.ssr": "vite --mode ssr", | ||
"devDependencies": { | ||
"@builder.io/qwik": "0.0.20-3", | ||
"@builder.io/qwik": "0.0.20-4", | ||
"@types/node": "17.0.31", | ||
@@ -20,0 +20,0 @@ "node-fetch": "2.6.7", |
@@ -5,2 +5,6 @@ //////////////////////////////////////////////////////////////////////// | ||
import { createContext } from '@builder.io/qwik'; | ||
export const TODOS = createContext<Todos>('TodoApp'); | ||
export interface TodoItem { | ||
@@ -7,0 +11,0 @@ completed: boolean; |
@@ -1,57 +0,5 @@ | ||
/* eslint-disable */ | ||
// @ts-ignore | ||
import { render } from '../server/entry.server.js'; | ||
import type { RenderToStringOptions, RenderToStringResult } from '@builder.io/qwik/server'; | ||
export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) => { | ||
try { | ||
const url = new URL(request.url); | ||
// Handle static assets | ||
if (/\.\w+$/.test(request.url)) { | ||
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/', | ||
}; | ||
// Generate Qwik SSR HTML | ||
const result: RenderToStringResult = await render(opts); | ||
// Create HTTP Response | ||
const response = new Response(result.html, { | ||
headers: { | ||
'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) { | ||
// 500 Error | ||
return new Response(String(e), { status: 500 }); | ||
} | ||
}; | ||
// Cloudflare Pages Functions | ||
// https://developers.cloudflare.com/pages/platform/functions/ | ||
export { onRequestGet } from '../server/entry.cloudflare.js'; |
{ | ||
"description": "Cloudflare Pages.", | ||
"scripts": { | ||
"build.ssr": "vite build --ssr src/entry.cloudflare.tsx", | ||
"serve": "wrangler pages dev ./dist" | ||
@@ -5,0 +6,0 @@ }, |
{ | ||
"description": "Express.js server.", | ||
"scripts": { | ||
"serve": "node app.js" | ||
"build.ssr": "vite build --ssr src/entry.express.tsx", | ||
"serve": "node server/entry.express.js" | ||
}, | ||
@@ -6,0 +7,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
158426
75
1997