create-qwik 0.0.39-dev20220801194759 → 0.0.39-dev20220805031634

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-qwik",
3
- "version": "0.0.39-dev20220801194759",
3
+ "version": "0.0.39-dev20220805031634",
4
4
  "description": "Interactive CLI and API for generating Qwik projects.",
5
5
  "bin": "create-qwik",
6
6
  "main": "index.js",
@@ -15,12 +15,12 @@
15
15
  "typecheck": "tsc --incremental --noEmit"
16
16
  },
17
17
  "devDependencies": {
18
- "@builder.io/qwik": "0.0.39-dev20220801194759",
18
+ "@builder.io/qwik": "0.0.39-dev20220805031634",
19
19
  "@types/eslint": "8.4.5",
20
20
  "@types/node": "latest",
21
21
  "@typescript-eslint/eslint-plugin": "5.30.7",
22
22
  "@typescript-eslint/parser": "5.30.7",
23
- "eslint-plugin-qwik": "0.0.39-dev20220801194759",
23
+ "eslint-plugin-qwik": "0.0.39-dev20220805031634",
24
24
  "eslint": "8.20.0",
25
25
  "node-fetch": "3.2.9",
26
26
  "typescript": "4.7.4",
@@ -30,6 +30,6 @@
30
30
  "homepage": "https://qwik.builder.io/",
31
31
  "private": true,
32
32
  "engines": {
33
- "node": ">=14"
33
+ "node": "^14.18.0 || >=16.0.0"
34
34
  }
35
35
  }
@@ -36,12 +36,13 @@ app.get('/*', async (req, res, next) => {
36
36
  // Render the Root component to a string
37
37
  const result = await render({
38
38
  stream: res,
39
- url: req.url,
40
39
  });
41
40
 
42
41
  // respond with SSR'd HTML
43
42
  if ('html' in result) {
44
43
  res.send((result as any).html);
44
+ } else {
45
+ res.end();
45
46
  }
46
47
  } catch (e) {
47
48
  // Error while server-side rendering
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "type": "module",
16
16
  "devDependencies": {
17
- "@builder.io/qwik-city": "0.0.26",
17
+ "@builder.io/qwik-city": "0.0.29",
18
18
  "vite-tsconfig-paths": "3.5.0"
19
19
  }
20
20
  }
@@ -1,11 +1,11 @@
1
1
  import { component$, Host } from '@builder.io/qwik';
2
- import { Content } from '@builder.io/qwik-city';
2
+ import { RouterOutlet } from '@builder.io/qwik-city';
3
3
 
4
4
  export const Body = component$(
5
5
  () => {
6
6
  return (
7
7
  <Host>
8
- <Content />
8
+ <RouterOutlet />
9
9
  </Host>
10
10
  );
11
11
  },
@@ -1,10 +1,10 @@
1
- import { component$, Host, useScopedStyles$ } from '@builder.io/qwik';
1
+ import { component$, Host, useStyles$ } from '@builder.io/qwik';
2
2
  import { useContent, useLocation, ContentMenu } from '@builder.io/qwik-city';
3
3
  import styles from './breadcrumbs.css?inline';
4
4
 
5
5
  export const Breadcrumbs = component$(
6
6
  () => {
7
- useScopedStyles$(styles);
7
+ useStyles$(styles);
8
8
 
9
9
  const { menu } = useContent();
10
10
  const loc = useLocation();
@@ -1,8 +1,8 @@
1
- import { component$, useScopedStyles$, useStore } from '@builder.io/qwik';
1
+ import { component$, useStyles$, useStore } from '@builder.io/qwik';
2
2
 
3
3
  export const Counter = component$(() => {
4
4
  const store = useStore({ count: 0 });
5
- useScopedStyles$(`
5
+ useStyles$(`
6
6
  .counter {
7
7
  border: 3px solid #1474ff;
8
8
  padding: 10px;
@@ -1,10 +1,10 @@
1
- import { component$, Host, useScopedStyles$ } from '@builder.io/qwik';
1
+ import { component$, Host, useStyles$ } from '@builder.io/qwik';
2
2
  import { useContent, Link, useLocation } from '@builder.io/qwik-city';
3
3
  import styles from './menu.css?inline';
4
4
 
5
5
  export const Menu = component$(
6
6
  () => {
7
- useScopedStyles$(styles);
7
+ useStyles$(styles);
8
8
 
9
9
  const { menu } = useContent();
10
10
  const loc = useLocation();
@@ -1,9 +1,9 @@
1
- import { component$, Host, Slot, useScopedStyles$ } from '@builder.io/qwik';
1
+ import { component$, Host, Slot, useStyles$ } from '@builder.io/qwik';
2
2
  import type { DocumentHead } from '@builder.io/qwik-city';
3
3
  import styles from './api.css?inline';
4
4
 
5
5
  export default component$(() => {
6
- useScopedStyles$(styles);
6
+ useStyles$(styles);
7
7
 
8
8
  return (
9
9
  <Host class="api">
@@ -4,7 +4,7 @@ import type { DocumentHead } from '@builder.io/qwik-city';
4
4
  export default component$(() => {
5
5
  return (
6
6
  <Host>
7
- <h1 onClick$={() => console.warn('hola')}>Welcome to Qwik City</h1>
7
+ <h1>Welcome to Qwik City</h1>
8
8
 
9
9
  <p>The meta-framework for Qwik.</p>
10
10
  </Host>
@@ -1,10 +1,9 @@
1
- import { Resource, component$, Host, useStore } from '@builder.io/qwik';
1
+ import { Resource, component$, Host } from '@builder.io/qwik';
2
2
  import { useEndpoint, useLocation, EndpointHandler, DocumentHead } from '@builder.io/qwik-city';
3
3
  import os from 'os';
4
4
 
5
5
  export default component$(() => {
6
- const { params, pathname } = useLocation();
7
- const store = useStore({ productFetchData: '' });
6
+ const { params } = useLocation();
8
7
 
9
8
  const resource = useEndpoint<typeof onGet>();
10
9
 
@@ -30,23 +29,6 @@ export default component$(() => {
30
29
 
31
30
  <p>(Artificial response delay of 250ms)</p>
32
31
 
33
- <p>
34
- <button
35
- onClick$={async () => {
36
- const rsp = await fetch(pathname, {
37
- headers: { accept: 'application/json' },
38
- });
39
- store.productFetchData = JSON.stringify(await rsp.json(), null, 2);
40
- }}
41
- >
42
- fetch("{pathname}") data
43
- </button>
44
- </p>
45
-
46
- <pre>
47
- <code>{store.productFetchData}</code>
48
- </pre>
49
-
50
32
  <hr />
51
33
 
52
34
  <ul>
@@ -67,13 +49,7 @@ export default component$(() => {
67
49
  );
68
50
  });
69
51
 
70
- export const head: DocumentHead<ProductData | null> = ({ data }) => {
71
- if (!data) {
72
- return {
73
- title: 'Product Not Found',
74
- };
75
- }
76
-
52
+ export const head: DocumentHead<ProductData> = ({ data }) => {
77
53
  return {
78
54
  title: `Product ${data.productId}, ${data.price}`,
79
55
  };
@@ -85,35 +61,49 @@ export const onGet: EndpointHandler<EndpointData> = async ({ params, response })
85
61
  // On the client, this same data can be requested with fetch() at the same URL, but also
86
62
  // requires the "accept: application/json" request header.
87
63
 
88
- // artificial slow response
89
- await new Promise<void>((resolve) => setTimeout(resolve, 250));
90
-
91
64
  if (params.id === 'shirt') {
92
65
  // Redirect, which will skip any rendering and the server will immediately redirect
93
66
  response.redirect('/products/tshirt');
94
67
  return;
95
68
  }
96
69
 
97
- const productPrice = PRODUCT_DB[params.id];
70
+ // artificially slow database call
71
+ const productData = await loadProduct(params.id);
98
72
 
99
- if (!productPrice) {
73
+ if (!productData) {
100
74
  // Product data not found
101
75
  // but the data is still given to the renderer to decide what to do
102
76
  response.status = 404;
103
- return null;
77
+ return;
104
78
  }
105
79
 
106
80
  // Found the product data
107
81
  // This same data is passed to the head() function
108
82
  // and in the component$() it can be access with useEndpoint()
109
83
  response.headers.set('Cache-Control', 'no-cache, no-store, no-fun');
110
- return {
111
- productId: params.id,
112
- price: productPrice,
113
- description: `Node ${process.versions.node} ${os.platform()} ${os.arch()} ${
114
- os.cpus()[0].model
115
- }`,
116
- };
84
+ return productData;
85
+ };
86
+
87
+ // our pretty awesome function to load product data
88
+ const loadProduct = (productId: string) => {
89
+ return new Promise<ProductData | null>((resolve) =>
90
+ setTimeout(() => {
91
+ const productPrice = PRODUCT_DB[productId];
92
+ if (!productPrice) {
93
+ return null;
94
+ }
95
+
96
+ const productData: ProductData = {
97
+ productId,
98
+ price: productPrice,
99
+ description: `Node ${process.versions.node} ${os.platform()} ${os.arch()} ${
100
+ os.cpus()[0].model
101
+ }`,
102
+ };
103
+
104
+ resolve(productData);
105
+ }, 250)
106
+ );
117
107
  };
118
108
 
119
109
  // Our pretty awesome database of prices
@@ -123,7 +113,7 @@ const PRODUCT_DB: Record<string, string> = {
123
113
  tshirt: '$18.96',
124
114
  };
125
115
 
126
- type EndpointData = ProductData | null;
116
+ type EndpointData = ProductData;
127
117
 
128
118
  interface ProductData {
129
119
  productId: string;
@@ -1,52 +1,6 @@
1
1
  import render from './entry.ssr';
2
+ import { qwikCity } from '@builder.io/qwik-city/middleware/cloudflare-pages';
2
3
 
3
- /**
4
- * Cloudflare Pages Request Handler
5
- */
6
- export const onRequest: PagesFunction = async ({ request, next, waitUntil }) => {
7
- try {
8
- const url = new URL(request.url);
4
+ const qwikCityMiddleware = qwikCity(render);
9
5
 
10
- // Handle static assets
11
- if (/\.\w+$/.test(request.url)) {
12
- return next(request);
13
- }
14
-
15
- // Do not using caching during development
16
- const useCache = url.hostname !== 'localhost' && request.method === 'GET';
17
-
18
- // Early return from cache
19
- const cache = await caches.open('custom:qwik');
20
- if (useCache) {
21
- const cachedResponse = await cache.match(request);
22
- if (cachedResponse) {
23
- return cachedResponse;
24
- }
25
- }
26
-
27
- // Generate Qwik SSR HTML
28
- const result = await render({
29
- url: request.url,
30
- });
31
-
32
- // Create HTTP Response
33
- const response = new Response(result.html, {
34
- headers: {
35
- 'Content-Type': 'text/html; charset=utf-8',
36
- 'Cache-Control': useCache
37
- ? `max-age=60, s-maxage=10, stale-while-revalidate=604800, stale-if-error=604800`
38
- : `no-cache, max-age=0`,
39
- },
40
- });
41
-
42
- if (useCache) {
43
- waitUntil(cache.put(request, response.clone()));
44
- }
45
-
46
- // Return Qwik SSR response
47
- return response;
48
- } catch (e) {
49
- // 500 Error
50
- return new Response(String(e), { status: 500 });
51
- }
52
- };
6
+ export const onRequestGet = [qwikCityMiddleware];
@@ -1,19 +1,30 @@
1
1
  import express from 'express';
2
2
  import { fileURLToPath } from 'url';
3
3
  import { join } from 'path';
4
- import cityPlan from '@qwik-city-plan';
5
4
  import { qwikCity } from '@builder.io/qwik-city/middleware/express';
6
5
  import render from './entry.ssr';
7
6
 
7
+ // directories where the static assets are located
8
+ const distDir = join(fileURLToPath(import.meta.url), '..', '..', 'dist');
9
+ const buildDir = join(distDir, 'build');
10
+
11
+ // create the Qwik City express middleware
12
+ const { router, notFound } = qwikCity(render);
13
+
14
+ // create the express server
8
15
  const app = express();
9
16
 
10
- app.use(
11
- qwikCity(render, {
12
- ...cityPlan,
13
- staticDir: join(fileURLToPath(import.meta.url), '..', '..', 'dist'),
14
- })
15
- );
17
+ // use Qwik City's page and endpoint handler
18
+ app.use(router);
19
+
20
+ // static asset handlers
21
+ app.use(`/build`, express.static(buildDir, { immutable: true, maxAge: '1y', index: false }));
22
+ app.use(express.static(distDir, { index: false }));
23
+
24
+ // use Qwik City's 404 handler
25
+ app.use(notFound);
16
26
 
27
+ // start the express server
17
28
  app.listen(8080, () => {
18
29
  /* eslint-disable */
19
30
  console.log(`http://localhost:8080/`);
@@ -0,0 +1,6 @@
1
+ import render from './entry.ssr';
2
+ import { qwikCity } from '@builder.io/qwik-city/middleware/netlify-edge';
3
+
4
+ const qwikCityHandler = qwikCity(render);
5
+
6
+ export default qwikCityHandler;
@@ -1,27 +0,0 @@
1
- import render from './entry.ssr';
2
-
3
- const handler = async (request: Request) => {
4
- try {
5
- // Handle static files
6
- if (/\.\w+$/.test(request.url)) {
7
- return;
8
- }
9
-
10
- const ssrResult = await render({
11
- url: request.url,
12
- base: '/build/',
13
- });
14
-
15
- const response = new Response(ssrResult.html, {
16
- headers: {
17
- 'Content-Type': 'text/html; charset=utf-8',
18
- },
19
- });
20
- return response;
21
- } catch (e) {
22
- // 500 Error
23
- return new Response(String(e), { status: 500 });
24
- }
25
- };
26
-
27
- export default handler;