@evjs/create-app 0.0.29 → 0.0.30

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.
Files changed (122) hide show
  1. package/dist/index.js +11 -12
  2. package/package.json +1 -1
  3. package/templates/api-routes/ev.config.ts +16 -0
  4. package/templates/{basic-plugins → api-routes}/package.json +2 -2
  5. package/templates/api-routes/src/api/demo.server.ts +5 -0
  6. package/templates/{basic-server-routes → api-routes}/src/pages/home.tsx +37 -0
  7. package/templates/{basic-server-routes → api-routes}/src/server.ts +3 -1
  8. package/templates/{basic-server-fns → basic}/README.md +7 -4
  9. package/templates/{basic-csr → basic}/ev.config.ts +1 -1
  10. package/templates/{basic-csr → basic}/package.json +2 -2
  11. package/templates/basic/src/main.tsx +37 -0
  12. package/templates/basic/src/pages/__root.tsx +49 -0
  13. package/templates/basic/src/pages/home.tsx +207 -0
  14. package/templates/complex-routing/README.md +13 -17
  15. package/templates/complex-routing/index.html +9 -9
  16. package/templates/complex-routing/package.json +4 -2
  17. package/templates/complex-routing/src/api/data.server.ts +86 -0
  18. package/templates/{basic-csr → complex-routing}/src/main.tsx +11 -6
  19. package/templates/complex-routing/src/pages/__root.tsx +60 -0
  20. package/templates/complex-routing/src/pages/catch.tsx +26 -0
  21. package/templates/complex-routing/src/pages/dashboard.tsx +79 -0
  22. package/templates/complex-routing/src/pages/home.tsx +35 -0
  23. package/templates/complex-routing/src/pages/posts/index.tsx +100 -0
  24. package/templates/complex-routing/src/pages/search.tsx +71 -0
  25. package/templates/complex-routing/src/pages/user.tsx +28 -0
  26. package/templates/complex-routing/tsconfig.json +6 -11
  27. package/templates/{websocket-fns → custom-ws-transport}/package.json +2 -2
  28. package/templates/{basic-mpa → mpa}/package.json +2 -2
  29. package/templates/{basic-server-fns → plugin-authoring}/package.json +2 -2
  30. package/templates/{server-fns-query → with-sqlite}/package.json +2 -2
  31. package/templates/with-tailwind/package.json +1 -1
  32. package/templates/{trpc-server-fns → with-trpc}/package.json +2 -2
  33. package/templates/basic-csr/README.md +0 -23
  34. package/templates/basic-csr/index.html +0 -11
  35. package/templates/basic-csr/src/pages/__root.tsx +0 -28
  36. package/templates/basic-csr/src/pages/about.tsx +0 -19
  37. package/templates/basic-csr/src/pages/home.tsx +0 -19
  38. package/templates/basic-csr/src/pages/posts/index.tsx +0 -63
  39. package/templates/basic-fns-ecma/README.md +0 -28
  40. package/templates/basic-fns-ecma/index.html +0 -11
  41. package/templates/basic-fns-ecma/package.json +0 -24
  42. package/templates/basic-fns-ecma/server.entry.mjs +0 -40
  43. package/templates/basic-fns-ecma/src/api/messages.server.ts +0 -33
  44. package/templates/basic-fns-ecma/src/main.tsx +0 -15
  45. package/templates/basic-fns-ecma/src/pages/__root.tsx +0 -19
  46. package/templates/basic-fns-ecma/src/pages/home.tsx +0 -76
  47. package/templates/basic-fns-ecma/swMock.entry.js +0 -85
  48. package/templates/basic-plugins/tsconfig.json +0 -18
  49. package/templates/basic-server-fns/src/pages/__root.tsx +0 -15
  50. package/templates/basic-server-fns/src/pages/home.tsx +0 -76
  51. package/templates/basic-server-routes/ev.config.ts +0 -7
  52. package/templates/basic-server-routes/package.json +0 -23
  53. package/templates/complex-routing/ev.config.ts +0 -14
  54. package/templates/complex-routing/src/about/main.tsx +0 -23
  55. package/templates/complex-routing/src/home/main.tsx +0 -23
  56. package/templates/configured-server-fns/README.md +0 -25
  57. package/templates/configured-server-fns/ev.config.ts +0 -39
  58. package/templates/configured-server-fns/index.html +0 -11
  59. package/templates/configured-server-fns/package.json +0 -23
  60. package/templates/configured-server-fns/src/api/users.server.ts +0 -22
  61. package/templates/configured-server-fns/src/pages/__root.tsx +0 -20
  62. package/templates/configured-server-fns/src/pages/home.tsx +0 -68
  63. package/templates/server-fns-query/README.md +0 -24
  64. package/templates/server-fns-query/src/api/posts.server.ts +0 -29
  65. package/templates/server-fns-query/src/api/users.server.ts +0 -49
  66. package/templates/server-fns-query/src/main.tsx +0 -21
  67. package/templates/server-fns-query/src/pages/__root.tsx +0 -22
  68. package/templates/server-fns-query/src/pages/home.tsx +0 -123
  69. package/templates/server-fns-query/src/pages/search.tsx +0 -64
  70. package/templates/server-fns-query/src/pages/user.tsx +0 -39
  71. package/templates/sqlite-server-fns/package.json +0 -23
  72. package/templates/sqlite-server-fns/src/main.tsx +0 -15
  73. package/templates/sqlite-server-fns/tsconfig.json +0 -17
  74. package/templates/trpc-server-fns/index.html +0 -11
  75. package/templates/trpc-server-fns/tsconfig.json +0 -17
  76. package/templates/websocket-fns/src/main.tsx +0 -15
  77. package/templates/websocket-fns/tsconfig.json +0 -17
  78. /package/templates/{basic-server-routes → api-routes}/README.md +0 -0
  79. /package/templates/{basic-server-routes → api-routes}/index.html +0 -0
  80. /package/templates/{basic-server-routes → api-routes}/src/api/health.routes.ts +0 -0
  81. /package/templates/{basic-server-routes → api-routes}/src/api/posts.routes.ts +0 -0
  82. /package/templates/{basic-server-routes → api-routes}/src/main.tsx +0 -0
  83. /package/templates/{basic-server-routes → api-routes}/src/pages/__root.tsx +0 -0
  84. /package/templates/{basic-fns-ecma → api-routes}/tsconfig.json +0 -0
  85. /package/templates/{basic-server-fns → basic}/index.html +0 -0
  86. /package/templates/{basic-server-fns → basic}/src/api/users.server.ts +0 -0
  87. /package/templates/{basic-server-fns → basic}/tsconfig.json +0 -0
  88. /package/templates/{websocket-fns → custom-ws-transport}/README.md +0 -0
  89. /package/templates/{websocket-fns → custom-ws-transport}/index.html +0 -0
  90. /package/templates/{websocket-fns → custom-ws-transport}/src/api/users.server.ts +0 -0
  91. /package/templates/{basic-server-fns → custom-ws-transport}/src/main.tsx +0 -0
  92. /package/templates/{websocket-fns → custom-ws-transport}/src/pages/__root.tsx +0 -0
  93. /package/templates/{websocket-fns → custom-ws-transport}/src/pages/home.tsx +0 -0
  94. /package/templates/{basic-server-routes → custom-ws-transport}/tsconfig.json +0 -0
  95. /package/templates/{basic-mpa → mpa}/README.md +0 -0
  96. /package/templates/{basic-mpa → mpa}/ev.config.ts +0 -0
  97. /package/templates/{basic-mpa → mpa}/index.html +0 -0
  98. /package/templates/{basic-mpa → mpa}/src/about/main.tsx +0 -0
  99. /package/templates/{basic-mpa → mpa}/src/home/main.tsx +0 -0
  100. /package/templates/{basic-csr → mpa}/tsconfig.json +0 -0
  101. /package/templates/{basic-plugins → plugin-authoring}/README.md +0 -0
  102. /package/templates/{basic-plugins → plugin-authoring}/ev.config.ts +0 -0
  103. /package/templates/{basic-plugins → plugin-authoring}/index.html +0 -0
  104. /package/templates/{basic-plugins → plugin-authoring}/src/main.tsx +0 -0
  105. /package/templates/{basic-plugins → plugin-authoring}/src/pages/__root.tsx +0 -0
  106. /package/templates/{basic-plugins → plugin-authoring}/src/pages/home.tsx +0 -0
  107. /package/templates/{basic-mpa → plugin-authoring}/tsconfig.json +0 -0
  108. /package/templates/{sqlite-server-fns → with-sqlite}/README.md +0 -0
  109. /package/templates/{sqlite-server-fns → with-sqlite}/index.html +0 -0
  110. /package/templates/{sqlite-server-fns → with-sqlite}/src/api/db.server.ts +0 -0
  111. /package/templates/{configured-server-fns → with-sqlite}/src/main.tsx +0 -0
  112. /package/templates/{sqlite-server-fns → with-sqlite}/src/pages/__root.tsx +0 -0
  113. /package/templates/{sqlite-server-fns → with-sqlite}/src/pages/home.tsx +0 -0
  114. /package/templates/{configured-server-fns → with-sqlite}/tsconfig.json +0 -0
  115. /package/templates/{trpc-server-fns → with-trpc}/README.md +0 -0
  116. /package/templates/{server-fns-query → with-trpc}/index.html +0 -0
  117. /package/templates/{trpc-server-fns → with-trpc}/src/api/trpc.server.ts +0 -0
  118. /package/templates/{trpc-server-fns → with-trpc}/src/main.tsx +0 -0
  119. /package/templates/{trpc-server-fns → with-trpc}/src/pages/__root.tsx +0 -0
  120. /package/templates/{trpc-server-fns → with-trpc}/src/pages/home.tsx +0 -0
  121. /package/templates/{trpc-server-fns → with-trpc}/src/trpc.ts +0 -0
  122. /package/templates/{server-fns-query → with-trpc}/tsconfig.json +0 -0
@@ -1,63 +0,0 @@
1
- import { createRoute, Link, Outlet } from "@evjs/client";
2
- import { rootRoute } from "../__root";
3
-
4
- const posts = [
5
- { id: "1", title: "First Post", body: "Hello world!" },
6
- { id: "2", title: "Second Post", body: "Another day, another post." },
7
- { id: "3", title: "Third Post", body: "Three's a charm." },
8
- ];
9
-
10
- function Posts() {
11
- return (
12
- <div style={{ display: "flex", gap: "1rem" }}>
13
- <ul style={{ listStyle: "none", padding: 0, minWidth: 160 }}>
14
- {posts.map((p) => (
15
- <li key={p.id} style={{ marginBottom: "0.25rem" }}>
16
- <Link
17
- to="/posts/$postId"
18
- params={{ postId: p.id }}
19
- activeProps={{ style: { fontWeight: "bold" } }}
20
- >
21
- {p.title}
22
- </Link>
23
- </li>
24
- ))}
25
- </ul>
26
- <Outlet />
27
- </div>
28
- );
29
- }
30
-
31
- export const postsRoute = createRoute({
32
- getParentRoute: () => rootRoute,
33
- path: "/posts",
34
- component: Posts,
35
- });
36
-
37
- function PostsIndex() {
38
- return <p style={{ color: "#6b7280" }}>Select a post.</p>;
39
- }
40
-
41
- export const postsIndexRoute = createRoute({
42
- getParentRoute: () => postsRoute,
43
- path: "/",
44
- component: PostsIndex,
45
- });
46
-
47
- function PostDetail() {
48
- const { postId } = postDetailRoute.useParams();
49
- const post = posts.find((p) => p.id === postId);
50
- if (!post) return <p>Post not found.</p>;
51
- return (
52
- <div>
53
- <h2>{post.title}</h2>
54
- <p>{post.body}</p>
55
- </div>
56
- );
57
- }
58
-
59
- export const postDetailRoute = createRoute({
60
- getParentRoute: () => postsRoute,
61
- path: "$postId",
62
- component: PostDetail,
63
- });
@@ -1,28 +0,0 @@
1
- # basic-fns-ecma
2
-
3
- Server functions with the ECMA/Fetch adapter — works on Deno, Bun, and edge runtimes.
4
-
5
- ## Run
6
-
7
- ```bash
8
- npm run dev -w example-basic-fns-ecma
9
-
10
- # Production
11
- npm run build -w example-basic-fns-ecma
12
- npm run start -w example-basic-fns-ecma
13
- ```
14
-
15
- ## Key Files
16
-
17
- | File | Purpose |
18
- |------|---------|
19
- | `src/main.tsx` | App bootstrap |
20
- | `src/routes.tsx` | Routes + components |
21
- | `src/api/messages.server.ts` | Server functions |
22
- | `server.entry.mjs` | Custom ECMA server entry using `@evjs/server/ecma` runtime |
23
-
24
- ## What It Demonstrates
25
-
26
- - `createFetchHandler` from `@evjs/server/ecma`
27
- - Portable server bundle (no Node.js-specific APIs)
28
- - Custom runtime configuration via `ev.config.ts`
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>ECMA Runtime Example</title>
7
- </head>
8
- <body>
9
- <div id="app"></div>
10
- </body>
11
- </html>
@@ -1,24 +0,0 @@
1
- {
2
- "name": "example-basic-fns-ecma",
3
- "version": "0.0.29",
4
- "private": true,
5
- "scripts": {
6
- "dev": "npx ev dev",
7
- "build": "npx ev build",
8
- "start": "node dist/server/start.mjs",
9
- "check-types": "tsc --noEmit"
10
- },
11
- "dependencies": {
12
- "react": "^19.2.4",
13
- "react-dom": "^19.2.4"
14
- },
15
- "devDependencies": {
16
- "@evjs/cli": "*",
17
- "@evjs/client": "*",
18
- "@evjs/ev": "*",
19
- "@evjs/server": "*",
20
- "@types/react": "^19.1.8",
21
- "@types/react-dom": "^19.1.8",
22
- "typescript": "^6.0.2"
23
- }
24
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * ECMA runtime adapter entry point.
3
- *
4
- * Loads the server bundle (which registers server functions via the runtime),
5
- * creates a Hono app, and exports a standard fetch handler.
6
- *
7
- * Works in any Fetch API-compatible runtime:
8
- * - Deno: `deno serve start.mjs`
9
- * - Bun: `bun run start.mjs`
10
- * - Edge runtimes: deploy as-is
11
- * - Node.js 18+: use with @hono/node-server
12
- */
13
-
14
- import { readFileSync } from "node:fs";
15
- import { createRequire } from "node:module";
16
-
17
- const require = createRequire(import.meta.url);
18
-
19
- // Read server manifest to find the entry bundle
20
- const manifest = JSON.parse(
21
- readFileSync(new URL("./manifest.json", import.meta.url), "utf-8"),
22
- );
23
- const bundle = require(`./server/${manifest.server.entry}`);
24
- const app = bundle.createApp();
25
-
26
- // Export via ECMA adapter — compatible with Deno, Bun, Workers
27
- const { createFetchHandler } = require("@evjs/server/ecma");
28
- const handler = createFetchHandler(app);
29
- export default handler;
30
-
31
- // For Node.js, start the server:
32
- if (typeof process !== "undefined" && process.argv[1]?.endsWith("start.mjs")) {
33
- const { serve } = await import("@hono/node-server");
34
- const port = Number(process.env.PORT) || 3001;
35
- serve({ fetch: app.fetch, port }, (info) => {
36
- console.log(
37
- `ECMA runtime server listening on http://localhost:${info.port}`,
38
- );
39
- });
40
- }
@@ -1,33 +0,0 @@
1
- "use server";
2
-
3
- /** Simulated message store. */
4
- const messages: { id: string; text: string; timestamp: string }[] = [
5
- {
6
- id: "1",
7
- text: "Hello from the ECMA runtime!",
8
- timestamp: new Date().toISOString(),
9
- },
10
- {
11
- id: "2",
12
- text: "This server runs on any Fetch-compatible runtime.",
13
- timestamp: new Date().toISOString(),
14
- },
15
- ];
16
-
17
- /** Get all messages. */
18
- export async function getMessages() {
19
- await new Promise((r) => setTimeout(r, 50));
20
- return messages;
21
- }
22
-
23
- /** Post a new message. */
24
- export async function postMessage(text: string) {
25
- await new Promise((r) => setTimeout(r, 50));
26
- const msg = {
27
- id: String(messages.length + 1),
28
- text,
29
- timestamp: new Date().toISOString(),
30
- };
31
- messages.push(msg);
32
- return msg;
33
- }
@@ -1,15 +0,0 @@
1
- import { createApp } from "@evjs/client";
2
- import { rootRoute } from "./pages/__root";
3
- import { messagesRoute } from "./pages/home";
4
-
5
- const routeTree = rootRoute.addChildren([messagesRoute]);
6
-
7
- const app = createApp({ routeTree });
8
-
9
- declare module "@tanstack/react-router" {
10
- interface Register {
11
- router: typeof app.router;
12
- }
13
- }
14
-
15
- app.render("#app");
@@ -1,19 +0,0 @@
1
- import { createRootRoute, Link, Outlet } from "@evjs/client";
2
-
3
- function Root() {
4
- return (
5
- <div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
6
- <h1>ECMA Runtime Example</h1>
7
- <p style={{ color: "#666" }}>
8
- Server bundle is environment-agnostic — works in Node.js, Deno, Bun, any
9
- Fetch-compatible runtime.
10
- </p>
11
- <nav style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
12
- <Link to="/">Messages</Link>
13
- </nav>
14
- <Outlet />
15
- </div>
16
- );
17
- }
18
-
19
- export const rootRoute = createRootRoute({ component: Root });
@@ -1,76 +0,0 @@
1
- import { createRoute } from "@evjs/client";
2
- import { useEffect, useState } from "react";
3
- import { getMessages, postMessage } from "../api/messages.server";
4
- import { rootRoute } from "./__root";
5
-
6
- function MessagesPage() {
7
- const [text, setText] = useState("");
8
- const [messages, setMessages] = useState<
9
- { id: string; text: string; timestamp: string }[]
10
- >([]);
11
- const [isLoading, setIsLoading] = useState(true);
12
-
13
- useEffect(() => {
14
- let mounted = true;
15
- getMessages()
16
- .then((data) => {
17
- if (mounted) {
18
- setMessages(data);
19
- setIsLoading(false);
20
- }
21
- })
22
- .catch((err) => {
23
- console.error(err);
24
- if (mounted) setIsLoading(false);
25
- });
26
- return () => {
27
- mounted = false;
28
- };
29
- }, []);
30
-
31
- async function handlePost(e: { preventDefault: () => void }) {
32
- e.preventDefault();
33
- if (!text) return;
34
- try {
35
- await postMessage(text);
36
- setText("");
37
- const data = await getMessages();
38
- setMessages(data);
39
- } catch (err) {
40
- console.error(err);
41
- }
42
- }
43
-
44
- if (isLoading) return <p>Loading messages from server…</p>;
45
-
46
- return (
47
- <div>
48
- <h2>Messages (via server functions)</h2>
49
- <ul>
50
- {messages.map((m) => (
51
- <li key={m.id}>
52
- <strong>{m.text}</strong>
53
- <br />
54
- <small style={{ color: "#999" }}>{m.timestamp}</small>
55
- </li>
56
- ))}
57
- </ul>
58
-
59
- <h3>Post a Message</h3>
60
- <form onSubmit={handlePost} style={{ display: "flex", gap: "0.5rem" }}>
61
- <input
62
- placeholder="Message"
63
- value={text}
64
- onChange={(e) => setText(e.target.value)}
65
- />
66
- <button type="submit">Send</button>
67
- </form>
68
- </div>
69
- );
70
- }
71
-
72
- export const messagesRoute = createRoute({
73
- getParentRoute: () => rootRoute,
74
- path: "/",
75
- component: MessagesPage,
76
- });
@@ -1,85 +0,0 @@
1
- /**
2
- * Service Worker adapter — runs server functions in the browser.
3
- *
4
- * Mirrors server.entry.mjs but for the Service Worker environment.
5
- * Intercepts /api/* requests (matching the default rpcEndpoint) and
6
- * handles them locally via Hono. Update the path prefix below if
7
- * using a custom rpcEndpoint.
8
- *
9
- * When running in Node.js (no native SW APIs), mock implementations
10
- * are provided so the entry can be tested outside a browser.
11
- */
12
- import { readFileSync } from "node:fs";
13
- import { createRequire } from "node:module";
14
-
15
- // ── Mock Service Worker APIs for Node.js testing ──
16
-
17
- if (typeof self === "undefined") {
18
- const listeners = {};
19
- globalThis.self = /** @type {any} */ ({
20
- addEventListener(type, handler) {
21
- if (!listeners[type]) {
22
- listeners[type] = [];
23
- }
24
- listeners[type].push(handler);
25
- },
26
- __listeners: listeners,
27
- });
28
- }
29
-
30
- if (typeof FetchEvent === "undefined") {
31
- globalThis.FetchEvent = class FetchEvent extends Event {
32
- /** @type {Request} */
33
- request;
34
- /** @type {Promise<Response> | Response | undefined} */
35
- _response;
36
-
37
- /**
38
- * @param {string} type
39
- * @param {{ request: Request }} init
40
- */
41
- constructor(type, init) {
42
- super(type);
43
- this.request = init.request;
44
- }
45
-
46
- /** @param {Promise<Response> | Response} response */
47
- respondWith(response) {
48
- this._response = response;
49
- }
50
- };
51
- }
52
-
53
- // ── Actual SW entry logic ──
54
-
55
- const require = createRequire(import.meta.url);
56
-
57
- const manifest = JSON.parse(
58
- readFileSync(new URL("./manifest.json", import.meta.url), "utf-8"),
59
- );
60
- const bundle = require(`./server/${manifest.server.entry}`);
61
- const app = bundle.createApp();
62
-
63
- // SW fetch event
64
- self.addEventListener("fetch", (event) => {
65
- const url = new URL(event.request.url);
66
- if (url.pathname.startsWith("/api/")) {
67
- event.respondWith(app.fetch(event.request));
68
- }
69
- });
70
-
71
- // ── Test helper: dispatch a mock FetchEvent and return the response ──
72
-
73
- /**
74
- * Dispatch a mock fetch event through the SW handler.
75
- * @param {Request} request
76
- * @returns {Promise<Response | undefined>}
77
- */
78
- export async function dispatchFetch(request) {
79
- const event = new FetchEvent("fetch", { request });
80
- const handlers = self.__listeners?.fetch || [];
81
- for (const handler of handlers) {
82
- handler(event);
83
- }
84
- return event._response ? await event._response : undefined;
85
- }
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "jsx": "react-jsx",
5
- "module": "ESNext",
6
- "lib": ["ESNext", "DOM", "DOM.Iterable"],
7
- "types": ["node"],
8
- "moduleResolution": "Bundler",
9
- "verbatimModuleSyntax": true,
10
- "noEmit": true,
11
- "skipLibCheck": true,
12
- "strict": true,
13
- "noUnusedLocals": true,
14
- "noUnusedParameters": true,
15
- "noFallthroughCasesInSwitch": true
16
- },
17
- "include": ["src"]
18
- }
@@ -1,15 +0,0 @@
1
- import { createRootRoute, Link, Outlet } from "@evjs/client";
2
-
3
- function Root() {
4
- return (
5
- <div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
6
- <h1>Server Functions Example</h1>
7
- <nav style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
8
- <Link to="/">Users</Link>
9
- </nav>
10
- <Outlet />
11
- </div>
12
- );
13
- }
14
-
15
- export const rootRoute = createRootRoute({ component: Root });
@@ -1,76 +0,0 @@
1
- import {
2
- createRoute,
3
- getFnQueryKey,
4
- useMutation,
5
- useQuery,
6
- useQueryClient,
7
- } from "@evjs/client";
8
- import { useState } from "react";
9
- import { createUser, getUsers } from "../api/users.server";
10
- import { rootRoute } from "./__root";
11
-
12
- console.log("***** ", getUsers, createUser);
13
-
14
- Object.assign(window, { getUsers, createUser });
15
-
16
- function UsersPage() {
17
- const [name, setName] = useState("");
18
- const [email, setEmail] = useState("");
19
- const queryClient = useQueryClient();
20
-
21
- // Use the framework's useQuery hook instead of manual useState + useEffect
22
- const { data: users = [], isLoading } = useQuery(getUsers);
23
-
24
- // Use useMutation for server function calls that modify data
25
- const createUserMutation = useMutation({
26
- mutationFn: createUser,
27
- onSuccess: () => {
28
- // Invalidate and refetch users list after successful creation
29
- queryClient.invalidateQueries({ queryKey: getFnQueryKey(getUsers) });
30
- setName("");
31
- setEmail("");
32
- },
33
- });
34
-
35
- function handleCreate(e: { preventDefault: () => void }) {
36
- e.preventDefault();
37
- if (!name || !email) return;
38
- createUserMutation.mutate({ name, email });
39
- }
40
-
41
- if (isLoading) return <p>Loading users from server…</p>;
42
-
43
- return (
44
- <div>
45
- <h2>Users (fetched via direct server function call)</h2>
46
- <ul>
47
- {users.map((u) => (
48
- <li key={u.id}>
49
- {u.name} — {u.email}
50
- </li>
51
- ))}
52
- </ul>
53
-
54
- <h3>Add User</h3>
55
- <form onSubmit={handleCreate} style={{ display: "flex", gap: "0.5rem" }}>
56
- <input
57
- placeholder="Name"
58
- value={name}
59
- onChange={(e) => setName(e.target.value)}
60
- />
61
- <input
62
- placeholder="Email"
63
- value={email}
64
- onChange={(e) => setEmail(e.target.value)}
65
- />
66
- <button type="submit">Create</button>
67
- </form>
68
- </div>
69
- );
70
- }
71
-
72
- export const usersRoute = createRoute({
73
- getParentRoute: () => rootRoute,
74
- path: "/",
75
- component: UsersPage,
76
- });
@@ -1,7 +0,0 @@
1
- import { defineConfig } from "@evjs/ev";
2
-
3
- export default defineConfig({
4
- server: {
5
- entry: "./src/server.ts",
6
- },
7
- });
@@ -1,23 +0,0 @@
1
- {
2
- "name": "example-basic-server-routes",
3
- "version": "0.0.29",
4
- "private": true,
5
- "scripts": {
6
- "dev": "npx ev dev",
7
- "build": "npx ev build",
8
- "check-types": "tsc --noEmit"
9
- },
10
- "dependencies": {
11
- "react": "^19.2.4",
12
- "react-dom": "^19.2.4"
13
- },
14
- "devDependencies": {
15
- "@evjs/cli": "*",
16
- "@evjs/client": "*",
17
- "@evjs/ev": "*",
18
- "@evjs/server": "*",
19
- "@types/react": "^19.1.8",
20
- "@types/react-dom": "^19.1.8",
21
- "typescript": "^6.0.2"
22
- }
23
- }
@@ -1,14 +0,0 @@
1
- import { defineConfig } from "@evjs/ev";
2
-
3
- export default defineConfig({
4
- server: false,
5
- html: "./index.html",
6
- pages: {
7
- home: {
8
- entry: "./src/home/main.tsx",
9
- },
10
- about: {
11
- entry: "./src/about/main.tsx",
12
- },
13
- },
14
- });
@@ -1,23 +0,0 @@
1
- import { createRoot } from "react-dom/client";
2
-
3
- function AboutPage() {
4
- return (
5
- <main style={{ fontFamily: "ui-sans-serif, system-ui", margin: "2rem" }}>
6
- <h1>About Page</h1>
7
- <p>
8
- This page is rendered from <code>src/about/main.tsx</code>.
9
- </p>
10
- <p>
11
- <a href="/home.html">Back to Home page</a>
12
- </p>
13
- </main>
14
- );
15
- }
16
-
17
- const rootEl = document.getElementById("app");
18
-
19
- if (!rootEl) {
20
- throw new Error("Missing #app mount element");
21
- }
22
-
23
- createRoot(rootEl).render(<AboutPage />);
@@ -1,23 +0,0 @@
1
- import { createRoot } from "react-dom/client";
2
-
3
- function HomePage() {
4
- return (
5
- <main style={{ fontFamily: "ui-sans-serif, system-ui", margin: "2rem" }}>
6
- <h1>Home Page</h1>
7
- <p>
8
- This page is rendered from <code>src/home/main.tsx</code>.
9
- </p>
10
- <p>
11
- <a href="/about.html">Go to About page</a>
12
- </p>
13
- </main>
14
- );
15
- }
16
-
17
- const rootEl = document.getElementById("app");
18
-
19
- if (!rootEl) {
20
- throw new Error("Missing #app mount element");
21
- }
22
-
23
- createRoot(rootEl).render(<HomePage />);
@@ -1,25 +0,0 @@
1
- # configured-server-fns
2
-
3
- Server functions with `ev.config.ts` and `useQuery` / `useMutation`.
4
-
5
- ## Run
6
-
7
- ```bash
8
- npm run dev -w example-configured-server-fns
9
- ```
10
-
11
- ## Key Files
12
-
13
- | File | Purpose |
14
- |------|---------|
15
- | `ev.config.ts` | Custom ports and settings |
16
- | `src/routes.tsx` | Routes with `useQuery` / `useMutation` |
17
- | `src/api/users.server.ts` | User CRUD functions |
18
-
19
- ## What It Demonstrates
20
-
21
- - `ev.config.ts` with `defineConfig` for custom ports
22
- - Plugin with `setup()` → `bundler: utoopack(...)` for type-safe bundler config
23
- - `useQuery(getUsers)` for fetching data with auto-generated keys
24
- - `useMutation({ mutationFn })` with `getFnQueryKey(getUsers)` for cache invalidation
25
- - Direct mutation args: `mutate({ name, email })` (not array-wrapped)
@@ -1,39 +0,0 @@
1
- import { defineConfig } from "@evjs/ev";
2
-
3
- /**
4
- * Advanced ev.config.ts example.
5
- *
6
- * This file demonstrates the available configuration options.
7
- * All fields are optional — evjs works out of the box with utoopack.
8
- */
9
- export default defineConfig({
10
- // Client entry point (default: "./src/main.tsx")
11
- entry: "./src/main.tsx",
12
-
13
- // HTML template (default: "./index.html")
14
- html: "./index.html",
15
-
16
- // Dev server options (merged with built-in defaults)
17
- dev: {
18
- // Dev server port (default: 3000)
19
- port: 4000,
20
-
21
- // Any dev server options can be added here:
22
- // https: true,
23
- },
24
-
25
- server: {
26
- // Server function endpoint path (default: "/api/fn")
27
- endpoint: "/api/fn",
28
-
29
- // Server runtime command (default: "node")
30
- // Supports: "node", "bun", "deno run --allow-net", etc.
31
- runtime: "node",
32
-
33
- // Dev server options
34
- dev: {
35
- // API server port in dev mode (default: 3001)
36
- port: 4001,
37
- },
38
- },
39
- });