@evjs/create-app 0.2.2 → 0.2.3
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/README.md +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -4
- package/templates/api-routes/README.md +14 -7
- package/templates/api-routes/ev.config.ts +1 -10
- package/templates/api-routes/package.json +1 -3
- package/templates/api-routes/src/apis/api/health.ts +13 -0
- package/templates/api-routes/src/apis/api/middleware.ts +15 -0
- package/templates/api-routes/src/apis/api/posts/$id.ts +50 -0
- package/templates/api-routes/src/apis/api/posts-store.ts +35 -0
- package/templates/api-routes/src/apis/api/posts.ts +34 -0
- package/templates/api-routes/src/layout/index.tsx +1 -1
- package/templates/api-routes/src/middleware.ts +10 -0
- package/templates/api-routes/src/pages/index.tsx +1 -1
- package/templates/api-routes/tsconfig.json +3 -0
- package/templates/basic/README.md +1 -1
- package/templates/basic/package.json +1 -3
- package/templates/basic/src/{api → apis}/users.server.ts +1 -1
- package/templates/basic/src/layout/index.tsx +1 -1
- package/templates/basic/src/pages/index.tsx +2 -2
- package/templates/basic/src/pages/search.tsx +2 -2
- package/templates/basic/src/pages/users/$userId.tsx +2 -2
- package/templates/basic/tsconfig.json +3 -0
- package/templates/complex-routing/package.json +1 -3
- package/templates/complex-routing/src/layout/index.tsx +1 -1
- package/templates/complex-routing/src/pages/dashboard.tsx +2 -2
- package/templates/complex-routing/src/pages/index.tsx +1 -1
- package/templates/complex-routing/src/pages/old-blog.tsx +1 -1
- package/templates/complex-routing/src/pages/posts/$postId.tsx +2 -2
- package/templates/complex-routing/src/pages/posts/index.tsx +2 -2
- package/templates/complex-routing/src/pages/search.tsx +2 -2
- package/templates/complex-routing/src/pages/users/$username.tsx +2 -2
- package/templates/complex-routing/tsconfig.json +4 -1
- package/templates/custom-ws-transport/README.md +1 -1
- package/templates/custom-ws-transport/package.json +1 -3
- package/templates/custom-ws-transport/src/layout/index.tsx +1 -1
- package/templates/custom-ws-transport/src/pages/index.tsx +2 -2
- package/templates/custom-ws-transport/tsconfig.json +3 -0
- package/templates/mpa/README.md +3 -2
- package/templates/mpa/ev.config.ts +4 -1
- package/templates/mpa/package.json +1 -1
- package/templates/mpa/src/pages/about.html +11 -0
- package/templates/mpa/tsconfig.json +3 -0
- package/templates/plugin-authoring/package.json +1 -3
- package/templates/plugin-authoring/src/pages/index.tsx +2 -2
- package/templates/plugin-authoring/tsconfig.json +3 -0
- package/templates/with-sqlite/README.md +1 -3
- package/templates/with-sqlite/package.json +1 -3
- package/templates/with-sqlite/src/{api → apis}/db.server.ts +1 -1
- package/templates/with-sqlite/src/layout/index.tsx +1 -1
- package/templates/with-sqlite/src/pages/index.tsx +3 -3
- package/templates/with-sqlite/tsconfig.json +3 -0
- package/templates/with-tailwind/ev.config.ts +4 -1
- package/templates/with-tailwind/package.json +1 -2
- package/templates/with-tailwind/src/layout/index.tsx +2 -2
- package/templates/with-tailwind/tsconfig.json +3 -0
- package/templates/with-trpc/README.md +1 -2
- package/templates/with-trpc/package.json +1 -3
- package/templates/with-trpc/src/{api → apis}/trpc.server.ts +1 -1
- package/templates/with-trpc/src/pages/index.tsx +3 -3
- package/templates/with-trpc/tsconfig.json +3 -0
- package/templates/api-routes/src/api/health.routes.ts +0 -17
- package/templates/api-routes/src/api/posts.routes.ts +0 -109
- package/templates/api-routes/src/server.ts +0 -13
- /package/templates/api-routes/src/{api → apis}/demo.server.ts +0 -0
- /package/templates/complex-routing/src/{api → apis}/data.server.ts +0 -0
- /package/templates/custom-ws-transport/src/{api → apis}/users.server.ts +0 -0
- /package/templates/plugin-authoring/src/{api → apis}/plugin.server.ts +0 -0
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ npx @evjs/create-app [name] [options]
|
|
|
24
24
|
|------|-------------|
|
|
25
25
|
| **`basic`** | Basic full-stack example with routing and server functions. |
|
|
26
26
|
| **`mpa`** | Multi-page application with separate page entries. |
|
|
27
|
-
| **`api-routes`** |
|
|
27
|
+
| **`api-routes`** | REST API routes via `server.routing` file routes. |
|
|
28
28
|
| **`complex-routing`** | Root layout, loaders, search params, and nested paths. |
|
|
29
29
|
| **`custom-ws-transport`** | Custom transport example using WebSockets. |
|
|
30
30
|
| **`plugin-authoring`** | Starter focused on plugin authoring and bundler hooks. |
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ export async function runCreateAppCli(argv = process.argv) {
|
|
|
44
44
|
{ title: "Basic (Routing + Server Functions)", value: "basic" },
|
|
45
45
|
{ title: "MPA (Multi-Page Application)", value: "mpa" },
|
|
46
46
|
{
|
|
47
|
-
title: "API Routes (
|
|
47
|
+
title: "API Routes (REST API via server file routes)",
|
|
48
48
|
value: "api-routes",
|
|
49
49
|
},
|
|
50
50
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evjs/create-app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Scaffold a new evjs project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"@types/prompts": "^2.4.9",
|
|
40
40
|
"typescript": "^6.0.2"
|
|
41
41
|
},
|
|
42
|
-
"homepage": "https://github.com/
|
|
42
|
+
"homepage": "https://github.com/afx-team/evjs#readme",
|
|
43
43
|
"bugs": {
|
|
44
|
-
"url": "https://github.com/
|
|
44
|
+
"url": "https://github.com/afx-team/evjs/issues"
|
|
45
45
|
},
|
|
46
46
|
"repository": {
|
|
47
47
|
"type": "git",
|
|
48
|
-
"url": "git+https://github.com/
|
|
48
|
+
"url": "git+https://github.com/afx-team/evjs.git"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"evjs",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# api-routes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
REST route handlers using `server.routing` file routes.
|
|
4
4
|
|
|
5
5
|
## Run
|
|
6
6
|
|
|
@@ -12,18 +12,22 @@ npm run dev
|
|
|
12
12
|
|
|
13
13
|
| File | Purpose |
|
|
14
14
|
|------|---------|
|
|
15
|
-
| `src/
|
|
16
|
-
| `src/api/
|
|
17
|
-
| `src/api/
|
|
15
|
+
| `src/middleware.ts` | Framework request middleware for all server requests |
|
|
16
|
+
| `src/apis/api/middleware.ts` | API route middleware for `/api/**` file routes |
|
|
17
|
+
| `src/apis/api/posts.ts` | List/create handlers for `/api/posts` |
|
|
18
|
+
| `src/apis/api/posts/$id.ts` | Dynamic handlers for `/api/posts/:id` |
|
|
19
|
+
| `src/apis/api/health.ts` | Health check endpoint |
|
|
20
|
+
| `src/apis/api/posts-store.ts` | Colocated helper module ignored by route discovery |
|
|
18
21
|
|
|
19
22
|
## What It Demonstrates
|
|
20
23
|
|
|
21
|
-
-
|
|
22
|
-
- Dynamic route
|
|
24
|
+
- Uppercase method exports (`GET`, `POST`, `PUT`, `DELETE`) for REST endpoints
|
|
25
|
+
- Dynamic route files (`$id.ts` -> `:id`)
|
|
23
26
|
- Query string parsing (`?limit=N`)
|
|
24
27
|
- Custom status codes (201, 204, 404)
|
|
25
28
|
- Auto `OPTIONS` and `405 Method Not Allowed`
|
|
26
|
-
-
|
|
29
|
+
- Framework request and API route `middleware.ts` conventions
|
|
30
|
+
- Colocated helper files without route exports
|
|
27
31
|
|
|
28
32
|
## Try It
|
|
29
33
|
|
|
@@ -52,4 +56,7 @@ curl http://localhost:3000/api/health
|
|
|
52
56
|
|
|
53
57
|
# Auto OPTIONS
|
|
54
58
|
curl -X OPTIONS http://localhost:3000/api/posts -i
|
|
59
|
+
|
|
60
|
+
# API route middleware short-circuit
|
|
61
|
+
curl -H 'x-block-api: true' http://localhost:3000/api/posts -i
|
|
55
62
|
```
|
|
@@ -2,15 +2,6 @@ import { defineConfig } from "@evjs/ev";
|
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
4
|
server: {
|
|
5
|
-
|
|
6
|
-
},
|
|
7
|
-
dev: {
|
|
8
|
-
proxy: [
|
|
9
|
-
{
|
|
10
|
-
context: ["/api"],
|
|
11
|
-
target: "http://localhost:3001",
|
|
12
|
-
changeOrigin: true,
|
|
13
|
-
},
|
|
14
|
-
],
|
|
5
|
+
routing: true,
|
|
15
6
|
},
|
|
16
7
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-api-routes",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
|
-
"@evjs/server": "*",
|
|
14
12
|
"react": "^19.2.4",
|
|
15
13
|
"react-dom": "^19.2.4"
|
|
16
14
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health check route handler.
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates a minimal single-method server file route.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const GET = async () => {
|
|
8
|
+
return Response.json({
|
|
9
|
+
status: "ok",
|
|
10
|
+
uptime: process.uptime(),
|
|
11
|
+
timestamp: new Date().toISOString(),
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from "@evjs/ev/request";
|
|
2
|
+
|
|
3
|
+
const middleware: MiddlewareHandler = async (ctx, next) => {
|
|
4
|
+
if (ctx.req.header("x-block-api") === "true") {
|
|
5
|
+
return Response.json(
|
|
6
|
+
{ error: "blocked by route middleware" },
|
|
7
|
+
{ status: 403 },
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
await next();
|
|
12
|
+
ctx.header("x-api-scope", "api");
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default middleware;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic route handlers for /api/posts/:id.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { posts } from "@/apis/api/posts-store";
|
|
6
|
+
|
|
7
|
+
interface RouteContext {
|
|
8
|
+
req: {
|
|
9
|
+
param(name: string): string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Get a single post. */
|
|
14
|
+
export const GET = async (_req: Request, ctx: RouteContext) => {
|
|
15
|
+
const id = ctx.req.param("id");
|
|
16
|
+
const post = posts.find((p) => p.id === id);
|
|
17
|
+
if (!post) {
|
|
18
|
+
return Response.json({ error: "Post not found" }, { status: 404 });
|
|
19
|
+
}
|
|
20
|
+
return Response.json(post);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Update a single post. */
|
|
24
|
+
export const PUT = async (req: Request, ctx: RouteContext) => {
|
|
25
|
+
const id = ctx.req.param("id");
|
|
26
|
+
const idx = posts.findIndex((p) => p.id === id);
|
|
27
|
+
if (idx === -1) {
|
|
28
|
+
return Response.json({ error: "Post not found" }, { status: 404 });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { title, body } = (await req.json()) as {
|
|
32
|
+
title?: string;
|
|
33
|
+
body?: string;
|
|
34
|
+
};
|
|
35
|
+
if (title) posts[idx].title = title;
|
|
36
|
+
if (body) posts[idx].body = body;
|
|
37
|
+
|
|
38
|
+
return Response.json(posts[idx]);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Delete a single post. */
|
|
42
|
+
export const DELETE = async (_req: Request, ctx: RouteContext) => {
|
|
43
|
+
const id = ctx.req.param("id");
|
|
44
|
+
const idx = posts.findIndex((p) => p.id === id);
|
|
45
|
+
if (idx === -1) {
|
|
46
|
+
return Response.json({ error: "Post not found" }, { status: 404 });
|
|
47
|
+
}
|
|
48
|
+
posts.splice(idx, 1);
|
|
49
|
+
return new Response(null, { status: 204 });
|
|
50
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Simulated post database shared by colocated server route modules. */
|
|
2
|
+
export interface Post {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
body: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const posts: Post[] = [
|
|
10
|
+
{
|
|
11
|
+
id: "1",
|
|
12
|
+
title: "Hello World",
|
|
13
|
+
body: "Welcome to evjs route handlers!",
|
|
14
|
+
createdAt: new Date().toISOString(),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "2",
|
|
18
|
+
title: "REST is not dead",
|
|
19
|
+
body: "Route handlers bring REST APIs to evjs.",
|
|
20
|
+
createdAt: new Date().toISOString(),
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
let nextId = 3;
|
|
25
|
+
|
|
26
|
+
export function createPost(input: { title: string; body: string }): Post {
|
|
27
|
+
const post: Post = {
|
|
28
|
+
id: String(nextId++),
|
|
29
|
+
title: input.title,
|
|
30
|
+
body: input.body,
|
|
31
|
+
createdAt: new Date().toISOString(),
|
|
32
|
+
};
|
|
33
|
+
posts.push(post);
|
|
34
|
+
return post;
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route handlers for the /api/posts REST endpoint.
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates:
|
|
5
|
+
* - Multiple HTTP methods on a single file path
|
|
6
|
+
* - JSON request/response
|
|
7
|
+
* - Custom status codes
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createPost, posts } from "./posts-store";
|
|
11
|
+
|
|
12
|
+
/** List posts. */
|
|
13
|
+
export const GET = async (req: Request) => {
|
|
14
|
+
const url = new URL(req.url);
|
|
15
|
+
const limit = Number(url.searchParams.get("limit")) || posts.length;
|
|
16
|
+
return Response.json(posts.slice(0, limit));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Create a post. */
|
|
20
|
+
export const POST = async (req: Request) => {
|
|
21
|
+
const { title, body } = (await req.json()) as {
|
|
22
|
+
title: string;
|
|
23
|
+
body: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (!title || !body) {
|
|
27
|
+
return Response.json(
|
|
28
|
+
{ error: "title and body are required" },
|
|
29
|
+
{ status: 400 },
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return Response.json(createPost({ title, body }), { status: 201 });
|
|
34
|
+
};
|
|
@@ -5,7 +5,7 @@ export default function Root({ children }: { children?: ReactNode }) {
|
|
|
5
5
|
<div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
|
|
6
6
|
<h1>Route Handlers Example</h1>
|
|
7
7
|
<p style={{ color: "#666" }}>
|
|
8
|
-
REST endpoints
|
|
8
|
+
REST endpoints discovered from <code>src/apis</code>
|
|
9
9
|
</p>
|
|
10
10
|
{children}
|
|
11
11
|
</div>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from "@evjs/ev/request";
|
|
2
|
+
|
|
3
|
+
const middleware: MiddlewareHandler = async (ctx, next) => {
|
|
4
|
+
const startedAt = Date.now();
|
|
5
|
+
await next();
|
|
6
|
+
ctx.header("x-example-server", "api-routes");
|
|
7
|
+
ctx.header("x-response-time-ms", String(Date.now() - startedAt));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default middleware;
|
|
@@ -173,7 +173,7 @@ function ServerFunctionCheck() {
|
|
|
173
173
|
const [message, setMessage] = useState<string>("");
|
|
174
174
|
|
|
175
175
|
async function checkServerFn() {
|
|
176
|
-
const { sayHello } = await import("
|
|
176
|
+
const { sayHello } = await import("@/apis/demo.server");
|
|
177
177
|
const result = await sayHello("World");
|
|
178
178
|
setMessage(result);
|
|
179
179
|
}
|
|
@@ -14,7 +14,7 @@ npm run dev
|
|
|
14
14
|
|------|---------|
|
|
15
15
|
| `src/layout/index.tsx` | SPA root layout |
|
|
16
16
|
| `src/pages/` | Page route files |
|
|
17
|
-
| `src/
|
|
17
|
+
| `src/apis/users.server.ts` | `"use server"` CRUD functions |
|
|
18
18
|
|
|
19
19
|
## What It Demonstrates
|
|
20
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-basic",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
|
-
"@evjs/server": "*",
|
|
14
12
|
"react": "^19.2.4",
|
|
15
13
|
"react-dom": "^19.2.4"
|
|
16
14
|
},
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
useMutation,
|
|
5
5
|
useQuery,
|
|
6
6
|
useQueryClient,
|
|
7
|
-
} from "@evjs/
|
|
7
|
+
} from "@evjs/ev/page";
|
|
8
8
|
import { useState } from "react";
|
|
9
|
-
import { createUser, getUsers } from "
|
|
9
|
+
import { createUser, getUsers } from "@/apis/users.server";
|
|
10
10
|
|
|
11
11
|
const cardStyle = {
|
|
12
12
|
border: "1px solid #e2e8f0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Link, usePageSearch, useQuery } from "@evjs/
|
|
2
|
-
import { getUsers } from "
|
|
1
|
+
import { Link, usePageSearch, useQuery } from "@evjs/ev/page";
|
|
2
|
+
import { getUsers } from "@/apis/users.server";
|
|
3
3
|
|
|
4
4
|
const cardStyle = {
|
|
5
5
|
border: "1px solid #e2e8f0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Link, usePageParams, useQuery } from "@evjs/
|
|
2
|
-
import { getUser } from "
|
|
1
|
+
import { Link, usePageParams, useQuery } from "@evjs/ev/page";
|
|
2
|
+
import { getUser } from "@/apis/users.server";
|
|
3
3
|
|
|
4
4
|
const cardStyle = {
|
|
5
5
|
border: "1px solid #e2e8f0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-complex-routing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
|
-
"@evjs/server": "*",
|
|
14
12
|
"react": "^19.2.4",
|
|
15
13
|
"react-dom": "^19.2.4"
|
|
16
14
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Link, usePageParams, useQuery } from "@evjs/
|
|
2
|
-
import { getUser } from "
|
|
1
|
+
import { Link, usePageParams, useQuery } from "@evjs/ev/page";
|
|
2
|
+
import { getUser } from "@/apis/data.server";
|
|
3
3
|
|
|
4
4
|
const styles = {
|
|
5
5
|
card: { border: "1px solid #e5e7eb", borderRadius: 8, padding: "1rem" },
|
|
@@ -14,7 +14,7 @@ npm run dev
|
|
|
14
14
|
|------|---------|
|
|
15
15
|
| `src/layout/index.tsx` | SPA root layout |
|
|
16
16
|
| `src/pages/index.tsx` | `initTransport` with WebSocket adapter and users CRUD UI |
|
|
17
|
-
| `src/
|
|
17
|
+
| `src/apis/users.server.ts` | Server functions |
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
## What It Demonstrates
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-custom-ws-transport",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
|
-
"@evjs/server": "*",
|
|
14
12
|
"react": "^19.2.4",
|
|
15
13
|
"react-dom": "^19.2.4"
|
|
16
14
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { initTransport } from "@evjs/
|
|
1
|
+
import { initTransport } from "@evjs/ev/transport";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
-
import { createUser, getUsers } from "
|
|
3
|
+
import { createUser, getUsers } from "@/apis/users.server";
|
|
4
4
|
|
|
5
5
|
// ── WebSocket Adapter ──
|
|
6
6
|
|
package/templates/mpa/README.md
CHANGED
|
@@ -19,15 +19,16 @@ npm run build
|
|
|
19
19
|
| File | Purpose |
|
|
20
20
|
|------|---------|
|
|
21
21
|
| `ev.config.ts` | Enables page MPA mode |
|
|
22
|
-
| `index.html` | Shared HTML template
|
|
22
|
+
| `index.html` | Shared fallback HTML template |
|
|
23
23
|
| `src/pages/home.tsx` | Home page component |
|
|
24
24
|
| `src/pages/about.tsx` | About page component |
|
|
25
|
+
| `src/pages/about.html` | Page-specific MPA HTML template for `about.tsx` |
|
|
25
26
|
|
|
26
27
|
## What It Demonstrates
|
|
27
28
|
|
|
28
29
|
- Multi-page build via `routing.mode: "mpa"`
|
|
29
30
|
- Independent router-free React page for each page file
|
|
30
|
-
- Shared HTML
|
|
31
|
+
- Shared HTML fallback plus a colocated page-specific HTML template
|
|
31
32
|
- Static links between pages
|
|
32
33
|
- No `@evjs/client`, `@evjs/server`, or generated `route-types.d.ts`
|
|
33
34
|
dependency is needed for this router-free client output
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-plugin-authoring",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
|
-
"@evjs/server": "*",
|
|
14
12
|
"react": "^19.2.4",
|
|
15
13
|
"react-dom": "^19.2.4"
|
|
16
14
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useQuery } from "@evjs/
|
|
2
|
-
import { getPluginMessage } from "
|
|
1
|
+
import { useQuery } from "@evjs/ev/page";
|
|
2
|
+
import { getPluginMessage } from "@/apis/plugin.server";
|
|
3
3
|
|
|
4
4
|
export default function Home() {
|
|
5
5
|
const { data, isLoading } = useQuery(getPluginMessage);
|
|
@@ -14,9 +14,7 @@ npm run dev
|
|
|
14
14
|
|------|---------|
|
|
15
15
|
| `src/layout/index.tsx` | SPA root layout |
|
|
16
16
|
| `src/pages/index.tsx` | Users list + todo management UI |
|
|
17
|
-
| `src/
|
|
18
|
-
| `src/api/users.server.ts` | User CRUD (create, delete, getUsers, getUser) |
|
|
19
|
-
| `src/api/todos.server.ts` | Todo CRUD (create, toggle, delete) |
|
|
17
|
+
| `src/apis/db.server.ts` | SQLite setup plus user and todo CRUD server functions |
|
|
20
18
|
|
|
21
19
|
## What It Demonstrates
|
|
22
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-with-sqlite",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
|
-
"@evjs/server": "*",
|
|
14
12
|
"react": "^19.2.4",
|
|
15
13
|
"react-dom": "^19.2.4"
|
|
16
14
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { DatabaseSync, type SQLOutputValue } from "node:sqlite";
|
|
5
|
-
import { ServerError } from "@evjs/
|
|
5
|
+
import { ServerError } from "@evjs/ev/request";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* SQLite database connection using Node.js built-in sqlite module.
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
useMutation,
|
|
4
4
|
useQuery,
|
|
5
5
|
useQueryClient,
|
|
6
|
-
} from "@evjs/
|
|
6
|
+
} from "@evjs/ev/page";
|
|
7
7
|
import { useState } from "react";
|
|
8
|
-
import type { Todo, User } from "
|
|
8
|
+
import type { Todo, User } from "@/apis/db.server";
|
|
9
9
|
import {
|
|
10
10
|
createTodo,
|
|
11
11
|
createUser,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
getTodos,
|
|
15
15
|
getUsers,
|
|
16
16
|
toggleTodo,
|
|
17
|
-
} from "
|
|
17
|
+
} from "@/apis/db.server";
|
|
18
18
|
|
|
19
19
|
// ── Users Page ──
|
|
20
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-with-tailwind",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
12
|
"@tailwindcss/typography": "^0.5.19",
|
|
14
13
|
"react": "^19.2.4",
|
|
@@ -14,8 +14,7 @@ npm run dev
|
|
|
14
14
|
|------|---------|
|
|
15
15
|
| `src/layout/index.tsx` | SPA root layout |
|
|
16
16
|
| `src/pages/index.tsx` | UI consuming both tRPC and evjs APIs |
|
|
17
|
-
| `src/
|
|
18
|
-
| `src/api/users.server.ts` | Standard evjs server functions |
|
|
17
|
+
| `src/apis/trpc.server.ts` | tRPC router and evjs server functions |
|
|
19
18
|
|
|
20
19
|
## What It Demonstrates
|
|
21
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-with-trpc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"check-types": "tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@evjs/client": "*",
|
|
12
11
|
"@evjs/ev": "*",
|
|
13
|
-
"@evjs/server": "*",
|
|
14
12
|
"@trpc/client": "^11.0.0-rc.825",
|
|
15
13
|
"@trpc/react-query": "^11.0.0-rc.825",
|
|
16
14
|
"@trpc/server": "^11.0.0-rc.825",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useQuery } from "@evjs/
|
|
1
|
+
import { useQuery } from "@evjs/ev/page";
|
|
2
2
|
import { createTRPCClient, type TRPCLink } from "@trpc/client";
|
|
3
3
|
import { observable } from "@trpc/server/observable";
|
|
4
4
|
import { useCallback, useEffect, useState } from "react";
|
|
5
|
-
import { getServerTime, trpcHandler } from "
|
|
6
|
-
import type { AppRouter } from "
|
|
5
|
+
import { getServerTime, trpcHandler } from "@/apis/trpc.server";
|
|
6
|
+
import type { AppRouter } from "@/trpc";
|
|
7
7
|
|
|
8
8
|
// ── tRPC Glue ──
|
|
9
9
|
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Health check route handler.
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates a minimal single-method route handler.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createRoute } from "@evjs/server";
|
|
8
|
-
|
|
9
|
-
export const healthHandler = createRoute("/api/health", {
|
|
10
|
-
GET: async () => {
|
|
11
|
-
return Response.json({
|
|
12
|
-
status: "ok",
|
|
13
|
-
uptime: process.uptime(),
|
|
14
|
-
timestamp: new Date().toISOString(),
|
|
15
|
-
});
|
|
16
|
-
},
|
|
17
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route handlers for the /api/posts REST endpoint.
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates:
|
|
5
|
-
* - Multiple HTTP methods on a single path
|
|
6
|
-
* - Dynamic route params
|
|
7
|
-
* - JSON request/response
|
|
8
|
-
* - Custom status codes
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { createRoute } from "@evjs/server";
|
|
12
|
-
|
|
13
|
-
/** Simulated post database. */
|
|
14
|
-
interface Post {
|
|
15
|
-
id: string;
|
|
16
|
-
title: string;
|
|
17
|
-
body: string;
|
|
18
|
-
createdAt: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const posts: Post[] = [
|
|
22
|
-
{
|
|
23
|
-
id: "1",
|
|
24
|
-
title: "Hello World",
|
|
25
|
-
body: "Welcome to evjs route handlers!",
|
|
26
|
-
createdAt: new Date().toISOString(),
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: "2",
|
|
30
|
-
title: "REST is not dead",
|
|
31
|
-
body: "Route handlers bring REST APIs to evjs.",
|
|
32
|
-
createdAt: new Date().toISOString(),
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
let nextId = 3;
|
|
37
|
-
|
|
38
|
-
/** List + Create posts. */
|
|
39
|
-
export const postsHandler = createRoute("/api/posts", {
|
|
40
|
-
GET: async (req) => {
|
|
41
|
-
// Support ?limit query param
|
|
42
|
-
const url = new URL(req.url);
|
|
43
|
-
const limit = Number(url.searchParams.get("limit")) || posts.length;
|
|
44
|
-
return Response.json(posts.slice(0, limit));
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
POST: async (req) => {
|
|
48
|
-
const { title, body } = (await req.json()) as {
|
|
49
|
-
title: string;
|
|
50
|
-
body: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
if (!title || !body) {
|
|
54
|
-
return Response.json(
|
|
55
|
-
{ error: "title and body are required" },
|
|
56
|
-
{ status: 400 },
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const post: Post = {
|
|
61
|
-
id: String(nextId++),
|
|
62
|
-
title,
|
|
63
|
-
body,
|
|
64
|
-
createdAt: new Date().toISOString(),
|
|
65
|
-
};
|
|
66
|
-
posts.push(post);
|
|
67
|
-
|
|
68
|
-
return Response.json(post, { status: 201 });
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
/** Get, Update, Delete a single post. */
|
|
73
|
-
export const postHandler = createRoute("/api/posts/:id", {
|
|
74
|
-
GET: async (_req, ctx) => {
|
|
75
|
-
const id = ctx.req.param("id");
|
|
76
|
-
const post = posts.find((p) => p.id === id);
|
|
77
|
-
if (!post) {
|
|
78
|
-
return Response.json({ error: "Post not found" }, { status: 404 });
|
|
79
|
-
}
|
|
80
|
-
return Response.json(post);
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
PUT: async (req, ctx) => {
|
|
84
|
-
const id = ctx.req.param("id");
|
|
85
|
-
const idx = posts.findIndex((p) => p.id === id);
|
|
86
|
-
if (idx === -1) {
|
|
87
|
-
return Response.json({ error: "Post not found" }, { status: 404 });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const { title, body } = (await req.json()) as {
|
|
91
|
-
title?: string;
|
|
92
|
-
body?: string;
|
|
93
|
-
};
|
|
94
|
-
if (title) posts[idx].title = title;
|
|
95
|
-
if (body) posts[idx].body = body;
|
|
96
|
-
|
|
97
|
-
return Response.json(posts[idx]);
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
DELETE: async (_req, ctx) => {
|
|
101
|
-
const id = ctx.req.param("id");
|
|
102
|
-
const idx = posts.findIndex((p) => p.id === id);
|
|
103
|
-
if (idx === -1) {
|
|
104
|
-
return Response.json({ error: "Post not found" }, { status: 404 });
|
|
105
|
-
}
|
|
106
|
-
posts.splice(idx, 1);
|
|
107
|
-
return new Response(null, { status: 204 });
|
|
108
|
-
},
|
|
109
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server entry — mounts route handlers onto the ev app.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createApp } from "@evjs/server";
|
|
6
|
-
import { healthHandler } from "./api/health.routes";
|
|
7
|
-
import { postHandler, postsHandler } from "./api/posts.routes";
|
|
8
|
-
|
|
9
|
-
const app = createApp({
|
|
10
|
-
routes: [healthHandler, postsHandler, postHandler],
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export default { fetch: app.fetch };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|