create-qwik 0.0.35-dev20220709120816 → 0.0.35

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.35-dev20220709120816",
3
+ "version": "0.0.35",
4
4
  "description": "Interactive CLI and API for generating Qwik projects.",
5
5
  "bin": "create-qwik",
6
6
  "main": "index.js",
@@ -14,16 +14,16 @@
14
14
  "typecheck": "tsc --incremental --noEmit"
15
15
  },
16
16
  "devDependencies": {
17
- "@builder.io/qwik": "0.0.35-dev20220709120816",
17
+ "@builder.io/qwik": "0.0.35",
18
18
  "@types/eslint": "8.4.5",
19
19
  "@types/node": "latest",
20
- "@typescript-eslint/eslint-plugin": "5.30.0",
21
- "@typescript-eslint/parser": "5.30.0",
22
- "eslint-plugin-qwik": "0.0.35-dev20220709120816",
23
- "eslint": "8.18.0",
20
+ "@typescript-eslint/eslint-plugin": "5.30.6",
21
+ "@typescript-eslint/parser": "5.30.6",
22
+ "eslint-plugin-qwik": "0.0.35",
23
+ "eslint": "8.19.0",
24
24
  "node-fetch": "2.6.7",
25
25
  "typescript": "4.7.4",
26
- "vite": "2.9.13"
26
+ "vite": "2.9.14"
27
27
  },
28
28
  "homepage": "https://qwik.builder.io/",
29
29
  "private": true,
@@ -9,7 +9,7 @@
9
9
  ]
10
10
  },
11
11
  "devDependencies": {
12
- "@builder.io/qwik-city": "0.0.16",
12
+ "@builder.io/qwik-city": "0.0.18",
13
13
  "vite-tsconfig-paths": "3.5.0"
14
14
  }
15
15
  }
@@ -1,12 +1,11 @@
1
1
  import { Content, Html } from '@builder.io/qwik-city';
2
- import cityPlan from '@qwik-city-plan';
3
2
  import { Head } from './components/head/head';
4
3
 
5
4
  import './global.css';
6
5
 
7
6
  export default () => {
8
7
  return (
9
- <Html lang="en" cityPlan={cityPlan}>
8
+ <Html lang="en">
10
9
  <Head />
11
10
  <body>
12
11
  <Content />
@@ -1,18 +1,18 @@
1
1
  import { component$, Host } from '@builder.io/qwik';
2
- import type { HeadComponent } from '@builder.io/qwik-city';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
3
3
 
4
4
  export default component$(() => {
5
5
  return (
6
6
  <Host>
7
7
  <h1>Sign In</h1>
8
- <form>
8
+ <form action="/api/on-sign-in" method="post">
9
9
  <label>
10
10
  <span>Username</span>
11
- <input type="text" />
11
+ <input name="username" type="text" />
12
12
  </label>
13
13
  <label>
14
14
  <span>Password</span>
15
- <input type="password" />
15
+ <input name="password" type="password" />
16
16
  </label>
17
17
  <button>Log In</button>
18
18
  </form>
@@ -20,10 +20,6 @@ export default component$(() => {
20
20
  );
21
21
  });
22
22
 
23
- export const head: HeadComponent = () => {
24
- return (
25
- <>
26
- <title>Sign In</title>
27
- </>
28
- );
23
+ export const head: DocumentHead = {
24
+ title: 'Sign In',
29
25
  };
@@ -1,5 +1,5 @@
1
1
  import { component$, Host } from '@builder.io/qwik';
2
- import type { HeadComponent } from '@builder.io/qwik-city';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
3
3
 
4
4
  export default component$(() => {
5
5
  return (
@@ -24,10 +24,6 @@ export default component$(() => {
24
24
  );
25
25
  });
26
26
 
27
- export const head: HeadComponent = () => {
28
- return (
29
- <>
30
- <title>Sign Up</title>
31
- </>
32
- );
27
+ export const head: DocumentHead = {
28
+ title: 'Sign Up',
33
29
  };
@@ -1,5 +1,5 @@
1
1
  import { component$, Host } from '@builder.io/qwik';
2
- import type { HeadComponent } from '@builder.io/qwik-city';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
3
3
 
4
4
  export default component$(() => {
5
5
  return (
@@ -12,10 +12,8 @@ export default component$(() => {
12
12
  );
13
13
  });
14
14
 
15
- export const head: HeadComponent = () => {
16
- return (
17
- <>
18
- <title>About Us</title>
19
- </>
20
- );
15
+ export const head: DocumentHead = () => {
16
+ return {
17
+ title: 'About US',
18
+ };
21
19
  };
@@ -1,42 +1,32 @@
1
1
  import type { EndpointHandler } from '@builder.io/qwik-city';
2
2
  import os from 'os';
3
3
 
4
- export const get: EndpointHandler = ({ request, params }) => {
5
- const data = {
6
- timestamp: Date.now(),
7
- method: request.method,
8
- url: request.url,
9
- params,
10
- os: os.platform(),
11
- arch: os.arch(),
12
- node: process.versions.node,
13
- };
14
-
15
- const res = new Response(JSON.stringify(data, null, 2), {
16
- headers: {
17
- 'Content-Type': 'application/json',
4
+ export const onGet: EndpointHandler = ({ request, params }) => {
5
+ return {
6
+ status: 200,
7
+ body: {
8
+ timestamp: Date.now(),
9
+ method: request.method,
10
+ url: request.url,
11
+ params,
12
+ os: os.platform(),
13
+ arch: os.arch(),
14
+ node: process.versions.node,
18
15
  },
19
- });
20
-
21
- return res;
22
- };
23
-
24
- export const post: EndpointHandler = async ({ request, params }) => {
25
- const data = {
26
- timestamp: Date.now(),
27
- method: request.method,
28
- url: request.url,
29
- params,
30
- os: os.platform(),
31
- arch: os.arch(),
32
- node: process.versions.node,
33
16
  };
17
+ };
34
18
 
35
- const res = new Response(JSON.stringify(data, null, 2), {
36
- headers: {
37
- 'Content-Type': 'application/json',
19
+ export const onPost: EndpointHandler = async ({ request, params }) => {
20
+ return {
21
+ status: 200,
22
+ body: {
23
+ timestamp: Date.now(),
24
+ method: request.method,
25
+ url: request.url,
26
+ params,
27
+ os: os.platform(),
28
+ arch: os.arch(),
29
+ node: process.versions.node,
38
30
  },
39
- });
40
-
41
- return res;
31
+ };
42
32
  };
@@ -1,5 +1,5 @@
1
1
  import { component$, Host, Slot, useScopedStyles$ } from '@builder.io/qwik';
2
- import type { HeadComponent } from '@builder.io/qwik-city';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
3
3
  import Footer from '../../../components/footer/footer';
4
4
  import Header from '../../../components/header/header';
5
5
  import styles from './api.css?inline';
@@ -31,10 +31,8 @@ export default component$(() => {
31
31
  );
32
32
  });
33
33
 
34
- export const head: HeadComponent = ({ location }) => {
35
- return (
36
- <>
37
- <title>API: {location.pathname}</title>
38
- </>
39
- );
34
+ export const head: DocumentHead = ({ pathname }) => {
35
+ return {
36
+ title: pathname,
37
+ };
40
38
  };
@@ -1,21 +1,16 @@
1
1
  import type { EndpointHandler } from '@builder.io/qwik-city';
2
2
  import os from 'os';
3
3
 
4
- export const get: EndpointHandler = ({ request }) => {
5
- const data = {
6
- timestamp: Date.now(),
7
- method: request.method,
8
- url: request.url,
9
- os: os.platform(),
10
- arch: os.arch(),
11
- node: process.versions.node,
12
- };
13
-
14
- const res = new Response(JSON.stringify(data, null, 2), {
15
- headers: {
16
- 'Content-Type': 'application/json',
4
+ export const onGet: EndpointHandler = ({ request }) => {
5
+ return {
6
+ status: 200,
7
+ body: {
8
+ timestamp: Date.now(),
9
+ method: request.method,
10
+ url: request.url,
11
+ os: os.platform(),
12
+ arch: os.arch(),
13
+ node: process.versions.node,
17
14
  },
18
- });
19
-
20
- return res;
15
+ };
21
16
  };
@@ -0,0 +1,67 @@
1
+ import type { EndpointHandler } from '@builder.io/qwik-city';
2
+
3
+ export type Cookie = Record<string, string>;
4
+ export type AuthResult = 'New Login' | 'Already Logged In' | 'Invalid Credentials';
5
+ export const STATUS: Record<AuthResult, { code: number; msg: string }> = {
6
+ 'New Login': {
7
+ code: 200,
8
+ msg: 'You are now logged in!',
9
+ },
10
+ 'Already Logged In': {
11
+ code: 200,
12
+ msg: 'You are now logged in!',
13
+ },
14
+ 'Invalid Credentials': {
15
+ code: 403,
16
+ msg: 'Incorrect user name and password',
17
+ },
18
+ };
19
+
20
+ export const post: EndpointHandler = async (ev: any) => {
21
+ const cookie = parseCookie(ev.request.headers.get('cookie'));
22
+ const formdata = await ev.request.formData();
23
+ const result = handleAuth(formdata, cookie);
24
+ const status = STATUS[result];
25
+ return {
26
+ status: status.code,
27
+ headers:
28
+ result == 'New Login'
29
+ ? {
30
+ 'Set-Cookie': `${AUTHTOKEN_NAME}=${generateToken()}; Secure; HttpOnly; Max-Age=${
31
+ 60 * 5
32
+ }`,
33
+ }
34
+ : {},
35
+ };
36
+ };
37
+
38
+ const AUTHTOKEN_NAME = 'qwikcity-auth-token';
39
+ export const handleAuth = (submission: FormData, cookie: Cookie): AuthResult => {
40
+ const username = submission.get('username');
41
+ const password = submission.get('password');
42
+ const token = cookie[AUTHTOKEN_NAME];
43
+ if (token !== undefined) {
44
+ return 'Already Logged In';
45
+ }
46
+ if (username == 'admin' && password == 'password') {
47
+ return 'New Login';
48
+ }
49
+ return 'Invalid Credentials';
50
+ };
51
+
52
+ export const generateToken = () => {
53
+ return Math.round(Math.random() * 1000);
54
+ };
55
+
56
+ export const parseCookie = (raw: string | null): Cookie => {
57
+ if (!raw) {
58
+ return {};
59
+ }
60
+ return raw
61
+ .split(';')
62
+ .map((v) => v.split('='))
63
+ .reduce((acc: Cookie, v) => {
64
+ acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
65
+ return acc;
66
+ }, {});
67
+ };
@@ -1,5 +1,5 @@
1
1
  import { component$, Host, Slot, useStyles$ } from '@builder.io/qwik';
2
- import type { HeadComponent } from '@builder.io/qwik-city';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
3
3
  import { Menu } from '../../../components/menu/menu';
4
4
  import styles from './docs.css?inline';
5
5
 
@@ -16,10 +16,8 @@ export default component$(() => {
16
16
  );
17
17
  });
18
18
 
19
- export const head: HeadComponent = ({ resolved }) => {
20
- return (
21
- <>
22
- <title>Docs: {resolved.title}</title>
23
- </>
24
- );
19
+ export const head: DocumentHead = ({ head }) => {
20
+ return {
21
+ title: `Docs: ${head.title}`,
22
+ };
25
23
  };
@@ -6,21 +6,27 @@ import { Counter } from '~/components/counter/counter';
6
6
 
7
7
  # Welcome
8
8
 
9
- Welcome to the fabolous Qwik City. QwikCity is our official kit to build amazing sites:
9
+ Welcome to the fabulous Qwik City. QwikCity is our official kit to build amazing sites:
10
10
 
11
11
  - 🐎 Powered by Qwik. Zero hydration and instant interactivity.
12
12
  - 🗃 File based routing (like Nextjs)
13
- - 🌏 Deploy easily to edge: Netlify, Cloudflare, Vercel, Deno...
13
+ - 🌏 Deploy easily to the edge: Netlify, Cloudflare, Vercel, Deno...
14
14
  - 📖 Author content directly in Markdown or MDX. MDX brings the best of markdown and JSX, allowing you to render Qwik components directly in markdown, like this one:
15
15
 
16
16
  <Counter />
17
17
 
18
18
  ## Next steps
19
19
 
20
- Open your editor and check the following:
20
+ Open your editor and check out the following:
21
21
 
22
- - **The `pages` folder**: This is where the main content lives. Adding you files (`.md`, `.mdx`, or `.tsx`) will automatically create new URLs.
23
- - **The `src/layout` folder**: This is what bring form to your content. Different kinds of pages, might need to be rendered by a different layout.
24
- This way you can reuse easily the layout across different content. By default, the `src/layout/default` is used.
25
- - **The `src/components` folder**: QwikCity is still a normal Qwik app. Any custom component, design systems, or funcionality should live here. Notice the `header`, `footer` and `content-nav` components. They are used by the `default` layout!
26
- - **The `src/utils` folder**: Place here business logic, or functions that are not components.
22
+ **The `src/routes` folder**
23
+
24
+ This is where the main content lives. Adding folders and / or files (`.md`, `.mdx`, or `.tsx`) will automatically create new URLs. For example, code saved at `routes/dashboard/settings/index.tsx` will be accessible via the URL path `/dashboard/settings`.
25
+
26
+ **The `src/routes/_layout` files and folders**
27
+
28
+ These bring form to your content. Since different pages may need to be rendered by different layouts, QwikCity provides the ability to scope layouts to specific routes, while still allowing for easy reuse across different content. For any page without its own layout defined, the `src/routes/_layout.tsx` is used by default.
29
+
30
+ **The `src/components` folder**
31
+
32
+ QwikCity is still a normal Qwik app. Any custom component, design systems, or functionality should live here. Notice the `header`, `footer` and `content-nav` components. They are used by the `default` layout!
@@ -1,5 +1,5 @@
1
1
  import { component$, Host } from '@builder.io/qwik';
2
- import type { HeadComponent } from '@builder.io/qwik-city';
2
+ import type { DocumentHead } from '@builder.io/qwik-city';
3
3
 
4
4
  export default component$(() => {
5
5
  return (
@@ -9,10 +9,8 @@ export default component$(() => {
9
9
  );
10
10
  });
11
11
 
12
- export const head: HeadComponent = () => {
13
- return (
14
- <>
15
- <title>Welcome!</title>
16
- </>
17
- );
12
+ export const head: DocumentHead = () => {
13
+ return {
14
+ title: 'Welcome!',
15
+ };
18
16
  };
@@ -1,7 +1,7 @@
1
1
  import express from 'express';
2
2
  import { join } from 'path';
3
3
  import cityPlan from '@qwik-city-plan';
4
- import { qwikCity } from '@builder.io/qwik-city/adaptors/express';
4
+ import { qwikCity } from '@builder.io/qwik-city/middleware/express';
5
5
  import { render } from './entry.ssr';
6
6
 
7
7
  const app = express();