@evjs/create-app 0.0.1-rc.27 → 0.0.2

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/dist/index.js CHANGED
@@ -29,6 +29,10 @@ program
29
29
  choices: [
30
30
  { title: "Basic CSR (Client-Side Rendering)", value: "basic-csr" },
31
31
  { title: "Basic Server Functions", value: "basic-server-fns" },
32
+ {
33
+ title: "Basic Server Routes (Programmatic REST API via route())",
34
+ value: "basic-server-routes",
35
+ },
32
36
  {
33
37
  title: "Configured Server Functions (ev.config.ts + Query)",
34
38
  value: "configured-server-fns",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evjs/create-app",
3
- "version": "0.0.1-rc.27",
3
+ "version": "0.0.2",
4
4
  "description": "Scaffold a new evjs project",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,15 +22,15 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "commander": "^12.1.0",
25
- "fs-extra": "^11.3.0",
25
+ "fs-extra": "^11.3.4",
26
26
  "picocolors": "^1.1.1",
27
27
  "prompts": "^2.4.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/fs-extra": "^11.0.4",
31
- "@types/node": "^22.13.5",
31
+ "@types/node": "^22.19.15",
32
32
  "@types/prompts": "^2.4.9",
33
- "typescript": "^5.7.3"
33
+ "typescript": "^6.0.2"
34
34
  },
35
35
  "homepage": "https://github.com/evaijs/evjs#readme",
36
36
  "bugs": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-basic-csr",
3
- "version": "0.0.1-rc.27",
3
+ "version": "0.0.2",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -15,8 +15,8 @@
15
15
  "@evjs/cli": "*",
16
16
  "@evjs/client": "*",
17
17
  "@evjs/server": "*",
18
- "@types/react": "^19.0.8",
19
- "@types/react-dom": "^19.0.3",
20
- "typescript": "^5.7.3"
18
+ "@types/react": "^19.1.8",
19
+ "@types/react-dom": "^19.1.8",
20
+ "typescript": "^6.0.2"
21
21
  }
22
22
  }
@@ -4,6 +4,7 @@
4
4
  "jsx": "react-jsx",
5
5
  "module": "ESNext",
6
6
  "lib": ["ESNext", "DOM", "DOM.Iterable"],
7
+ "types": ["node"],
7
8
  "moduleResolution": "Bundler",
8
9
  "verbatimModuleSyntax": true,
9
10
  "noEmit": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-basic-server-fns",
3
- "version": "0.0.1-rc.27",
3
+ "version": "0.0.2",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -17,6 +17,6 @@
17
17
  "@evjs/server": "*",
18
18
  "@types/react": "^19.1.8",
19
19
  "@types/react-dom": "^19.1.8",
20
- "typescript": "^5.7.3"
20
+ "typescript": "^6.0.2"
21
21
  }
22
22
  }
@@ -0,0 +1,248 @@
1
+
2
+ > example-basic-server-fns@0.0.0 dev
3
+ > ev dev
4
+
5
+ 11:30:23.781 INF evjs·cli Using 'convention-based defaults'
6
+ 11:30:23.847 INF evjs·cli Starting development server...
7
+ <w> [webpack-dev-server] "hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.
8
+ <i> [webpack-dev-server] [HPM] Proxy created: /api -> http://localhost:3001
9
+ <i> [webpack-dev-server] Project is running at:
10
+ <i> [webpack-dev-server] Loopback: http://localhost:3000/, http://[::1]:3000/
11
+ <i> [webpack-dev-server] On Your Network (IPv4): http://30.230.67.161:3000/
12
+ <i> [webpack-dev-server] On Your Network (IPv6): http://[fd00:1:1001:3300:403f:c64:3d22:618]:3000/
13
+ <i> [webpack-dev-server] Content not from webpack is served from '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/public' directory
14
+ 11:30:24.394 INF evjs·cli Server bundle detected, starting 'node' API...
15
+ assets by path ../ 37.4 KiB
16
+ asset ../server/main.js 36.8 KiB [compared for emit] 1 related asset
17
+ asset ../manifest.json 556 bytes [compared for emit]
18
+ asset index.js 1.81 MiB [compared for emit] (name: main) 1 related asset
19
+ asset index.html 292 bytes [compared for emit]
20
+ orphan modules 199 KiB [orphan] 41 modules
21
+ runtime modules 28.1 KiB 13 modules
22
+ modules by path ../../node_modules/ 1.57 MiB 116 modules
23
+ modules by path ../../packages/ 13 KiB
24
+ modules by path ../../packages/client/esm/*.js 10.8 KiB
25
+ ../../packages/client/esm/index.js 1000 bytes [built] [code generated]
26
+ + 5 modules
27
+ modules by path ../../packages/shared/esm/*.js 2.25 KiB
28
+ ../../packages/shared/esm/index.js 316 bytes [built] [code generated]
29
+ ../../packages/shared/esm/constants.js 309 bytes [built] [code generated]
30
+ + 2 modules
31
+ modules by path ./src/ 15.3 KiB
32
+ ./src/main.tsx 151 bytes [built] [code generated]
33
+ ./src/routes.tsx 14.3 KiB [built] [code generated]
34
+ ./src/api/users.server.ts 889 bytes [built] [code generated]
35
+ client (webpack 5.105.4) compiled successfully in 343 ms
36
+ [SERVER_TRACE] Request hit: http://localhost:3001/api/fn POST
37
+ [SERVER_TRACE] Parsing JSON...
38
+ [SERVER_TRACE] Parsed successfully: test
39
+ [SERVER_TRACE] Dispatching: test
40
+ [SERVER_TRACE] Dispatch returned!
41
+ assets by status 37.1 KiB [cached] 2 assets
42
+ assets by status 1.81 MiB [emitted]
43
+ assets by path *.js 1.81 MiB
44
+ asset index.js 1.81 MiB [emitted] (name: main) 1 related asset
45
+ asset main.f0309d981bf523e0dc6b.hot-update.js 369 bytes [emitted] [immutable] [hmr] (name: main) 1 related asset
46
+ asset ../manifest.json 644 bytes [emitted]
47
+ asset main.f0309d981bf523e0dc6b.hot-update.json 28 bytes [emitted] [immutable] [hmr]
48
+ Entrypoint main 1.81 MiB (1.97 MiB) = index.js 1.81 MiB main.f0309d981bf523e0dc6b.hot-update.js 369 bytes 2 auxiliary assets
49
+ cached modules 1.79 MiB [cached] 170 modules
50
+ runtime modules 28.1 KiB 13 modules
51
+ client (webpack 5.105.4) compiled successfully in 68 ms
52
+ assets by status 292 bytes [cached] 1 asset
53
+ assets by path *.js 1.81 MiB
54
+ asset index.js 1.81 MiB [emitted] (name: main) 1 related asset
55
+ asset main.c8cca34a363f98cff40e.hot-update.js 369 bytes [emitted] [immutable] [hmr] (name: main) 1 related asset
56
+ assets by path ../ 38.3 KiB
57
+ asset ../server/main.js 37.6 KiB [emitted] 1 related asset
58
+ asset ../manifest.json 681 bytes [emitted]
59
+ asset main.c8cca34a363f98cff40e.hot-update.json 28 bytes [emitted] [immutable] [hmr]
60
+ Entrypoint main 1.81 MiB (1.97 MiB) = index.js 1.81 MiB main.c8cca34a363f98cff40e.hot-update.js 369 bytes 2 auxiliary assets
61
+ cached modules 1.79 MiB [cached] 170 modules
62
+ runtime modules 28.1 KiB 13 modules
63
+ client (webpack 5.105.4) compiled successfully in 52 ms
64
+ Restarting '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'
65
+ assets by status 1.84 MiB [cached] 3 assets
66
+ asset ../manifest.json 667 bytes [emitted]
67
+ cached modules 1.79 MiB (javascript) 28.1 KiB (runtime) [cached] 183 modules
68
+ client (webpack 5.105.4) compiled successfully in 29 ms
69
+ assets by status 292 bytes [cached] 1 asset
70
+ assets by path *.js 1.81 MiB
71
+ asset index.js 1.81 MiB [emitted] (name: main) 1 related asset
72
+ asset main.3e842c143c5b24617c4b.hot-update.js 369 bytes [emitted] [immutable] [hmr] (name: main) 1 related asset
73
+ assets by path ../ 38.2 KiB
74
+ asset ../server/main.js 37.5 KiB [emitted] 1 related asset
75
+ asset ../manifest.json 755 bytes [emitted]
76
+ asset main.3e842c143c5b24617c4b.hot-update.json 28 bytes [emitted] [immutable] [hmr]
77
+ Entrypoint main 1.81 MiB (1.97 MiB) = index.js 1.81 MiB main.3e842c143c5b24617c4b.hot-update.js 369 bytes 2 auxiliary assets
78
+ cached modules 1.79 MiB [cached] 170 modules
79
+ runtime modules 28.1 KiB 13 modules
80
+ client (webpack 5.105.4) compiled successfully in 48 ms
81
+ Restarting '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'
82
+ assets by status 292 bytes [cached] 1 asset
83
+ assets by path *.js 1.81 MiB
84
+ asset index.js 1.81 MiB [emitted] (name: main) 1 related asset
85
+ asset main.eebe779e480ccaf73117.hot-update.js 369 bytes [emitted] [immutable] [hmr] (name: main) 1 related asset
86
+ assets by path ../ 38.5 KiB
87
+ asset ../server/main.js 37.7 KiB [emitted] 1 related asset
88
+ asset ../manifest.json 792 bytes [emitted]
89
+ asset main.eebe779e480ccaf73117.hot-update.json 28 bytes [emitted] [immutable] [hmr]
90
+ Entrypoint main 1.81 MiB (1.97 MiB) = index.js 1.81 MiB main.eebe779e480ccaf73117.hot-update.js 369 bytes 2 auxiliary assets
91
+ cached modules 1.79 MiB [cached] 170 modules
92
+ runtime modules 28.1 KiB 13 modules
93
+ client (webpack 5.105.4) compiled successfully in 54 ms
94
+ assets by status 1.84 MiB [cached] 3 assets
95
+ asset ../manifest.json 778 bytes [emitted]
96
+ cached modules 1.79 MiB (javascript) 28.1 KiB (runtime) [cached] 183 modules
97
+ client (webpack 5.105.4) compiled successfully in 22 ms
98
+ Restarting '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'
99
+ node:events:486
100
+ throw er; // Unhandled 'error' event
101
+ ^
102
+
103
+ Error: listen EADDRINUSE: address already in use :::3001
104
+ at Server.setupListenHandle [as _listen2] (node:net:1940:16)
105
+ at listenInCluster (node:net:1997:12)
106
+ at Server.listen (node:net:2102:7)
107
+ at serve (file:///Users/xusd320/Codes/github/evjs/node_modules/@hono/node-server/dist/index.mjs:581:10)
108
+ at serve (file:///Users/xusd320/Codes/github/evjs/packages/server/esm/environments/node.js:13:20)
109
+ at Object.<anonymous> (/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs:4:1)
110
+ at Module._compile (node:internal/modules/cjs/loader:1761:14)
111
+ at Object..js (node:internal/modules/cjs/loader:1893:10)
112
+ at Module.load (node:internal/modules/cjs/loader:1481:32)
113
+ at Module._load (node:internal/modules/cjs/loader:1300:12)
114
+ Emitted 'error' event on Server instance at:
115
+ at emitErrorNT (node:net:1976:8)
116
+ at process.processTicksAndRejections (node:internal/process/task_queues:89:21) {
117
+ code: 'EADDRINUSE',
118
+ errno: -48,
119
+ syscall: 'listen',
120
+ address: '::',
121
+ port: 3001
122
+ }
123
+
124
+ Node.js v24.12.0
125
+ Failed running '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'. Waiting for file changes before restarting...
126
+ assets by status 38 KiB [cached] 2 assets
127
+ assets by status 1.83 MiB [emitted]
128
+ assets by path *.js 1.83 MiB
129
+ asset index.js 1.81 MiB [emitted] (name: main) 1 related asset
130
+ asset main.4d9c77c2cdfec106f1f4.hot-update.js 17.5 KiB [emitted] [immutable] [hmr] (name: main) 1 related asset
131
+ asset ../manifest.json 866 bytes [emitted]
132
+ asset main.4d9c77c2cdfec106f1f4.hot-update.json 28 bytes [emitted] [immutable] [hmr]
133
+ Entrypoint main 1.83 MiB (1.97 MiB) = index.js 1.81 MiB main.4d9c77c2cdfec106f1f4.hot-update.js 17.5 KiB 2 auxiliary assets
134
+ cached modules 1.78 MiB [cached] 169 modules
135
+ runtime modules 28.1 KiB 13 modules
136
+ ./src/routes.tsx 14.8 KiB [built] [code generated]
137
+ client (webpack 5.105.4) compiled successfully in 62 ms
138
+ assets by status 1.85 MiB [cached] 3 assets
139
+ asset ../manifest.json 852 bytes [emitted]
140
+ cached modules 1.79 MiB (javascript) 28.1 KiB (runtime) [cached] 181 modules
141
+ javascript modules 1.53 KiB
142
+ ../../packages/shared/esm/constants.js 309 bytes [built]
143
+ ../../packages/shared/esm/errors.js 1.22 KiB [built]
144
+ client (webpack 5.105.4) compiled successfully in 32 ms
145
+ assets by status 1.85 MiB [cached] 3 assets
146
+ asset ../manifest.json 889 bytes [emitted]
147
+ cached modules 1.79 MiB (javascript) 28.1 KiB (runtime) [cached] 181 modules
148
+ javascript modules 742 bytes
149
+ ../../packages/shared/esm/index.js 316 bytes [built]
150
+ ../../packages/shared/esm/http.js 426 bytes [built]
151
+ client (webpack 5.105.4) compiled successfully in 26 ms
152
+ assets by status 1.85 MiB [cached] 3 assets
153
+ asset ../manifest.json 926 bytes [emitted]
154
+ cached modules 1.79 MiB (javascript) 28.1 KiB (runtime) [cached] 182 modules
155
+ ../../packages/client/esm/context.js 677 bytes [built]
156
+ client (webpack 5.105.4) compiled successfully in 23 ms
157
+ assets by status 1.85 MiB [cached] 3 assets
158
+ asset ../manifest.json 963 bytes [emitted]
159
+ cached modules 1.79 MiB (javascript) 28.1 KiB (runtime) [cached] 178 modules
160
+ javascript modules 10.1 KiB
161
+ ../../packages/client/esm/index.js 1000 bytes [built]
162
+ ../../packages/client/esm/app.js 1.63 KiB [built]
163
+ ../../packages/client/esm/transport.js 4.62 KiB [built]
164
+ ../../packages/client/esm/query.js 2.14 KiB [built]
165
+ ../../packages/client/esm/route.js 735 bytes [built]
166
+ client (webpack 5.105.4) compiled successfully in 30 ms
167
+ Restarting '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'
168
+ assets by status 1.85 MiB [cached] 3 assets
169
+ asset ../manifest.json 1000 bytes [emitted]
170
+ cached modules 1.8 MiB (javascript) 28.1 KiB (runtime) [cached] 183 modules
171
+ client (webpack 5.105.4) compiled successfully in 24 ms
172
+ assets by status 1.85 MiB [cached] 3 assets
173
+ asset ../manifest.json 1.01 KiB [emitted]
174
+ cached modules 1.8 MiB (javascript) 28.1 KiB (runtime) [cached] 183 modules
175
+ client (webpack 5.105.4) compiled successfully in 27 ms
176
+ <e> [webpack-dev-middleware] ModuleNotFoundError: Module not found: Error: Can't resolve '@evjs/server/register' in '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/src/api'
177
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/Compilation.js:2073:28
178
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/NormalModuleFactory.js:1041:13
179
+ <e> at eval (eval at create (/Users/xusd320/Codes/github/evjs/node_modules/tapable/lib/HookCodeFactory.js:31:10), <anonymous>:10:1)
180
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/NormalModuleFactory.js:437:22
181
+ <e> at eval (eval at create (/Users/xusd320/Codes/github/evjs/node_modules/tapable/lib/HookCodeFactory.js:31:10), <anonymous>:9:1)
182
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/NormalModuleFactory.js:622:22
183
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/NormalModuleFactory.js:181:10
184
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/NormalModuleFactory.js:894:25
185
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/NormalModuleFactory.js:1126:8
186
+ <e> at /Users/xusd320/Codes/github/evjs/node_modules/webpack/lib/NormalModuleFactory.js:1255:5
187
+ <e> resolve '@evjs/server/register' in '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/src/api'
188
+ <e> Parsed request is a module
189
+ <e> using description file: /Users/xusd320/Codes/github/evjs/examples/basic-server-fns/package.json (relative path: ./src/api)
190
+ <e> Field 'browser' doesn't contain a valid alias configuration
191
+ <e> resolve as module
192
+ <e> /Users/xusd320/Codes/github/evjs/examples/basic-server-fns/src/api/node_modules doesn't exist or is not a directory
193
+ <e> /Users/xusd320/Codes/github/evjs/examples/basic-server-fns/src/node_modules doesn't exist or is not a directory
194
+ <e> /Users/xusd320/Codes/github/evjs/examples/basic-server-fns/node_modules doesn't exist or is not a directory
195
+ <e> /Users/xusd320/Codes/github/evjs/examples/node_modules doesn't exist or is not a directory
196
+ <e> looking for modules in /Users/xusd320/Codes/github/evjs/node_modules
197
+ <e> existing directory /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server
198
+ <e> using description file: /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server/package.json (relative path: .)
199
+ <e> using exports field: ./esm/functions/register.js
200
+ <e> using description file: /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server/package.json (relative path: ./esm/functions/register.js)
201
+ <e> no extension
202
+ <e> Field 'browser' doesn't contain a valid alias configuration
203
+ <e> /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server/esm/functions/register.js doesn't exist
204
+ <e> .tsx
205
+ <e> Field 'browser' doesn't contain a valid alias configuration
206
+ <e> /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server/esm/functions/register.js.tsx doesn't exist
207
+ <e> .ts
208
+ <e> Field 'browser' doesn't contain a valid alias configuration
209
+ <e> /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server/esm/functions/register.js.ts doesn't exist
210
+ <e> .js
211
+ <e> Field 'browser' doesn't contain a valid alias configuration
212
+ <e> /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server/esm/functions/register.js.js doesn't exist
213
+ <e> as directory
214
+ <e> /Users/xusd320/Codes/github/evjs/node_modules/@evjs/server/esm/functions/register.js doesn't exist
215
+ <e> /Users/xusd320/Codes/github/node_modules doesn't exist or is not a directory
216
+ <e> /Users/xusd320/Codes/node_modules doesn't exist or is not a directory
217
+ <e> /Users/xusd320/node_modules doesn't exist or is not a directory
218
+ <e> /Users/node_modules doesn't exist or is not a directory
219
+ <e> /node_modules doesn't exist or is not a directory
220
+ Restarting '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'
221
+ node:events:486
222
+ throw er; // Unhandled 'error' event
223
+ ^
224
+
225
+ Error: listen EADDRINUSE: address already in use :::3001
226
+ at Server.setupListenHandle [as _listen2] (node:net:1940:16)
227
+ at listenInCluster (node:net:1997:12)
228
+ at Server.listen (node:net:2102:7)
229
+ at serve (file:///Users/xusd320/Codes/github/evjs/node_modules/@hono/node-server/dist/index.mjs:581:10)
230
+ at serve (file:///Users/xusd320/Codes/github/evjs/packages/server/esm/environments/node.js:13:20)
231
+ at Object.<anonymous> (/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs:4:1)
232
+ at Module._compile (node:internal/modules/cjs/loader:1761:14)
233
+ at Object..js (node:internal/modules/cjs/loader:1893:10)
234
+ at Module.load (node:internal/modules/cjs/loader:1481:32)
235
+ at Module._load (node:internal/modules/cjs/loader:1300:12)
236
+ Emitted 'error' event on Server instance at:
237
+ at emitErrorNT (node:net:1976:8)
238
+ at process.processTicksAndRejections (node:internal/process/task_queues:89:21) {
239
+ code: 'EADDRINUSE',
240
+ errno: -48,
241
+ syscall: 'listen',
242
+ address: '::',
243
+ port: 3001
244
+ }
245
+
246
+ Node.js v24.12.0
247
+ Failed running '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'. Waiting for file changes before restarting...
248
+ Restarting '/Users/xusd320/Codes/github/evjs/examples/basic-server-fns/dist/server/_dev_start.cjs'
@@ -5,6 +5,7 @@
5
5
  "jsx": "react-jsx",
6
6
  "module": "ESNext",
7
7
  "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
+ "types": ["node"],
8
9
  "moduleResolution": "Bundler",
9
10
  "outDir": "./dist",
10
11
  "rootDir": "./src",
@@ -0,0 +1,55 @@
1
+ # basic-server-routes
2
+
3
+ Programmatic REST route handlers using `route()`.
4
+
5
+ ## Run
6
+
7
+ ```bash
8
+ npm run dev -w example-basic-server-routes
9
+ ```
10
+
11
+ ## Key Files
12
+
13
+ | File | Purpose |
14
+ |------|---------|
15
+ | `src/server.ts` | Mounts route handlers via `createApp({ routeHandlers })` |
16
+ | `src/api/posts.routes.ts` | CRUD route handlers for `/api/posts` |
17
+ | `src/api/health.routes.ts` | Health check endpoint |
18
+
19
+ ## What It Demonstrates
20
+
21
+ - `route(path, { GET, POST, PUT, DELETE })` for REST endpoints
22
+ - Dynamic route params (`:id`)
23
+ - Query string parsing (`?limit=N`)
24
+ - Custom status codes (201, 204, 404)
25
+ - Auto `OPTIONS` and `405 Method Not Allowed`
26
+ - Mounting handlers via `createApp({ routeHandlers: [...] })`
27
+
28
+ ## Try It
29
+
30
+ ```bash
31
+ # List posts
32
+ curl http://localhost:3000/api/posts
33
+
34
+ # Create a post
35
+ curl -X POST http://localhost:3000/api/posts \
36
+ -H 'Content-Type: application/json' \
37
+ -d '{"title":"New Post","body":"Hello!"}'
38
+
39
+ # Get single post
40
+ curl http://localhost:3000/api/posts/1
41
+
42
+ # Update a post
43
+ curl -X PUT http://localhost:3000/api/posts/1 \
44
+ -H 'Content-Type: application/json' \
45
+ -d '{"title":"Updated Title"}'
46
+
47
+ # Delete a post
48
+ curl -X DELETE http://localhost:3000/api/posts/1
49
+
50
+ # Health check
51
+ curl http://localhost:3000/api/health
52
+
53
+ # Auto OPTIONS
54
+ curl -X OPTIONS http://localhost:3000/api/posts -i
55
+ ```
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "@evjs/cli";
2
+
3
+ export default defineConfig({
4
+ server: {
5
+ entry: "./src/server.ts",
6
+ },
7
+ });
@@ -0,0 +1,11 @@
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>Route Handlers Example</title>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ </body>
11
+ </html>
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "example-basic-server-routes",
3
+ "version": "0.0.2",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "ev dev",
7
+ "build": "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/server": "*",
18
+ "@types/react": "^19.1.8",
19
+ "@types/react-dom": "^19.1.8",
20
+ "typescript": "^6.0.2"
21
+ }
22
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Health check route handler.
3
+ *
4
+ * Demonstrates a minimal single-method route handler.
5
+ */
6
+
7
+ import { route } from "@evjs/server";
8
+
9
+ export const healthHandler = route("/api/health", {
10
+ GET: async () => {
11
+ return Response.json({
12
+ status: "ok",
13
+ uptime: process.uptime(),
14
+ timestamp: new Date().toISOString(),
15
+ });
16
+ },
17
+ });
@@ -0,0 +1,109 @@
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 { route } 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 = route("/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 = route("/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
+ });
@@ -0,0 +1,12 @@
1
+ import { createApp } from "@evjs/client";
2
+ import { routeTree } from "./routes";
3
+
4
+ const app = createApp({ routeTree });
5
+
6
+ declare module "@tanstack/react-router" {
7
+ interface Register {
8
+ router: typeof app.router;
9
+ }
10
+ }
11
+
12
+ app.render("#app");
@@ -0,0 +1,226 @@
1
+ import { createRootRoute, createRoute, Outlet } from "@evjs/client";
2
+ import { useState } from "react";
3
+
4
+ // ── Types ──
5
+
6
+ interface Post {
7
+ id: string;
8
+ title: string;
9
+ body: string;
10
+ createdAt: string;
11
+ }
12
+
13
+ // ── Root Route ──
14
+
15
+ function Root() {
16
+ return (
17
+ <div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
18
+ <h1>Route Handlers Example</h1>
19
+ <p style={{ color: "#666" }}>
20
+ REST endpoints powered by <code>route()</code>
21
+ </p>
22
+ <Outlet />
23
+ </div>
24
+ );
25
+ }
26
+
27
+ const rootRoute = createRootRoute({ component: Root });
28
+
29
+ // ── Posts Page ──
30
+
31
+ function PostsPage() {
32
+ const [posts, setPosts] = useState<Post[]>([]);
33
+ const [isLoading, setIsLoading] = useState(true);
34
+ const [error, setError] = useState<string | null>(null);
35
+ const [title, setTitle] = useState("");
36
+ const [body, setBody] = useState("");
37
+ const [isCreating, setIsCreating] = useState(false);
38
+
39
+ // Fetch posts from REST endpoint
40
+ async function fetchPosts() {
41
+ setIsLoading(true);
42
+ setError(null);
43
+ try {
44
+ const res = await fetch("/api/posts");
45
+ if (!res.ok) throw new Error(`Failed: ${res.status}`);
46
+ const data = await res.json();
47
+ setPosts(data);
48
+ } catch (err) {
49
+ setError(err instanceof Error ? err.message : String(err));
50
+ } finally {
51
+ setIsLoading(false);
52
+ }
53
+ }
54
+
55
+ // Create a new post via POST
56
+ async function handleCreate(e: React.FormEvent) {
57
+ e.preventDefault();
58
+ if (!title.trim() || !body.trim()) return;
59
+
60
+ setIsCreating(true);
61
+ try {
62
+ const res = await fetch("/api/posts", {
63
+ method: "POST",
64
+ headers: { "Content-Type": "application/json" },
65
+ body: JSON.stringify({ title, body }),
66
+ });
67
+ if (!res.ok) throw new Error(`Failed: ${res.status}`);
68
+ setTitle("");
69
+ setBody("");
70
+ await fetchPosts();
71
+ } catch (err) {
72
+ setError(err instanceof Error ? err.message : String(err));
73
+ } finally {
74
+ setIsCreating(false);
75
+ }
76
+ }
77
+
78
+ // Delete a post via DELETE
79
+ async function handleDelete(id: string) {
80
+ try {
81
+ const res = await fetch(`/api/posts/${id}`, { method: "DELETE" });
82
+ if (!res.ok) throw new Error(`Failed: ${res.status}`);
83
+ await fetchPosts();
84
+ } catch (err) {
85
+ setError(err instanceof Error ? err.message : String(err));
86
+ }
87
+ }
88
+
89
+ // Initial fetch
90
+ useState(() => {
91
+ fetchPosts();
92
+ });
93
+
94
+ return (
95
+ <div>
96
+ <h2>Posts</h2>
97
+
98
+ {error && <p style={{ color: "red" }}>Error: {error}</p>}
99
+
100
+ {isLoading ? (
101
+ <p>
102
+ Loading posts from <code>GET /api/posts</code>…
103
+ </p>
104
+ ) : (
105
+ <ul style={{ listStyle: "none", padding: 0 }}>
106
+ {posts.map((post) => (
107
+ <li
108
+ key={post.id}
109
+ style={{
110
+ border: "1px solid #ddd",
111
+ borderRadius: 8,
112
+ padding: "0.75rem 1rem",
113
+ marginBottom: "0.5rem",
114
+ display: "flex",
115
+ justifyContent: "space-between",
116
+ alignItems: "center",
117
+ }}
118
+ >
119
+ <div>
120
+ <strong>{post.title}</strong>
121
+ <p style={{ margin: "0.25rem 0 0", color: "#555" }}>
122
+ {post.body}
123
+ </p>
124
+ </div>
125
+ <button
126
+ type="button"
127
+ onClick={() => handleDelete(post.id)}
128
+ style={{
129
+ background: "none",
130
+ border: "1px solid #c00",
131
+ color: "#c00",
132
+ borderRadius: 4,
133
+ padding: "0.25rem 0.5rem",
134
+ cursor: "pointer",
135
+ flexShrink: 0,
136
+ }}
137
+ >
138
+ Delete
139
+ </button>
140
+ </li>
141
+ ))}
142
+ {posts.length === 0 && (
143
+ <li style={{ color: "#999" }}>No posts yet.</li>
144
+ )}
145
+ </ul>
146
+ )}
147
+
148
+ <h3>Create Post</h3>
149
+ <form
150
+ onSubmit={handleCreate}
151
+ style={{
152
+ display: "flex",
153
+ flexDirection: "column",
154
+ gap: "0.5rem",
155
+ maxWidth: 400,
156
+ }}
157
+ >
158
+ <input
159
+ placeholder="Title"
160
+ value={title}
161
+ onChange={(e) => setTitle(e.target.value)}
162
+ style={{ padding: "0.5rem" }}
163
+ />
164
+ <textarea
165
+ placeholder="Body"
166
+ value={body}
167
+ onChange={(e) => setBody(e.target.value)}
168
+ rows={3}
169
+ style={{ padding: "0.5rem" }}
170
+ />
171
+ <button
172
+ type="submit"
173
+ disabled={isCreating}
174
+ style={{ padding: "0.5rem", cursor: "pointer" }}
175
+ >
176
+ {isCreating ? "Creating…" : "Create Post"}
177
+ </button>
178
+ </form>
179
+
180
+ <h3 style={{ marginTop: "1.5rem" }}>Health Check</h3>
181
+ <HealthCheck />
182
+ </div>
183
+ );
184
+ }
185
+
186
+ // ── Health Check Component ──
187
+
188
+ function HealthCheck() {
189
+ const [health, setHealth] = useState<Record<string, unknown> | null>(null);
190
+
191
+ async function checkHealth() {
192
+ const res = await fetch("/api/health");
193
+ setHealth(await res.json());
194
+ }
195
+
196
+ return (
197
+ <div>
198
+ <button
199
+ type="button"
200
+ onClick={checkHealth}
201
+ style={{ padding: "0.5rem", cursor: "pointer" }}
202
+ >
203
+ GET /api/health
204
+ </button>
205
+ {health && (
206
+ <pre
207
+ style={{ background: "#f5f5f5", padding: "0.75rem", borderRadius: 4 }}
208
+ >
209
+ {JSON.stringify(health, null, 2)}
210
+ </pre>
211
+ )}
212
+ </div>
213
+ );
214
+ }
215
+
216
+ // ── Route ──
217
+
218
+ const postsRoute = createRoute({
219
+ getParentRoute: () => rootRoute,
220
+ path: "/",
221
+ component: PostsPage,
222
+ });
223
+
224
+ // ── Route Tree ──
225
+
226
+ export const routeTree = rootRoute.addChildren([postsRoute]);
@@ -0,0 +1,11 @@
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
+ export const app = createApp({
10
+ routeHandlers: [healthHandler, postsHandler, postHandler],
11
+ });
@@ -0,0 +1,17 @@
1
+ {
2
+ "include": ["src"],
3
+ "compilerOptions": {
4
+ "target": "ESNext",
5
+ "jsx": "react-jsx",
6
+ "module": "ESNext",
7
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
+ "types": ["node"],
9
+ "moduleResolution": "Bundler",
10
+ "outDir": "./dist",
11
+ "rootDir": "./src",
12
+ "skipLibCheck": true,
13
+ "strict": true,
14
+ "noEmit": true,
15
+ "verbatimModuleSyntax": true
16
+ }
17
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-complex-routing",
3
- "version": "0.0.1-rc.27",
3
+ "version": "0.0.2",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -15,8 +15,8 @@
15
15
  "@evjs/cli": "*",
16
16
  "@evjs/client": "*",
17
17
  "@evjs/server": "*",
18
- "@types/react": "^19.0.8",
19
- "@types/react-dom": "^19.0.3",
20
- "typescript": "^5.7.3"
18
+ "@types/react": "^19.1.8",
19
+ "@types/react-dom": "^19.1.8",
20
+ "typescript": "^6.0.2"
21
21
  }
22
22
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-configured-server-fns",
3
- "version": "0.0.1-rc.27",
3
+ "version": "0.0.2",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -17,6 +17,6 @@
17
17
  "@evjs/server": "*",
18
18
  "@types/react": "^19.1.8",
19
19
  "@types/react-dom": "^19.1.8",
20
- "typescript": "^5.7.3"
20
+ "typescript": "^6.0.2"
21
21
  }
22
22
  }
@@ -5,6 +5,7 @@
5
5
  "jsx": "react-jsx",
6
6
  "module": "ESNext",
7
7
  "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
+ "types": ["node"],
8
9
  "moduleResolution": "Bundler",
9
10
  "outDir": "./dist",
10
11
  "rootDir": "./src",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-tailwind",
3
- "version": "0.0.1-rc.27",
3
+ "version": "0.0.2",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -17,13 +17,13 @@
17
17
  "@evjs/client": "*",
18
18
  "@evjs/server": "*",
19
19
  "@tailwindcss/postcss": "^4.1.10",
20
- "@types/react": "^19.0.8",
21
- "@types/react-dom": "^19.0.3",
20
+ "@types/react": "^19.1.8",
21
+ "@types/react-dom": "^19.1.8",
22
22
  "css-loader": "^7.1.2",
23
23
  "postcss": "^8.5.6",
24
24
  "postcss-loader": "^8.1.1",
25
25
  "style-loader": "^4.0.0",
26
26
  "tailwindcss": "^4.1.10",
27
- "typescript": "^5.7.3"
27
+ "typescript": "^6.0.2"
28
28
  }
29
29
  }
@@ -0,0 +1 @@
1
+ declare module "*.css";
@@ -4,6 +4,7 @@
4
4
  "jsx": "react-jsx",
5
5
  "module": "ESNext",
6
6
  "lib": ["ESNext", "DOM", "DOM.Iterable"],
7
+ "types": ["node"],
7
8
  "moduleResolution": "Bundler",
8
9
  "verbatimModuleSyntax": true,
9
10
  "noEmit": true,