File tree Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Original file line number Diff line number Diff line change 4
4
"check" : " deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx" ,
5
5
"cli" : " echo \" import '\\ $fresh/src/dev/cli.ts'\" | deno run --unstable -A -" ,
6
6
"manifest" : " deno task cli manifest $(pwd)" ,
7
- "start" : " deno run -A --watch=src/static/,src/routes/ src/dev.ts" ,
7
+ "start" : " deno run -A --watch=src/static/,src/routes/ --unstable src/dev.ts" ,
8
8
"build" : " deno run -A src/dev.ts build" ,
9
9
"preview" : " deno run -A src/main.ts" ,
10
10
"update" : " deno run -A -r https://fresh.deno.dev/update ."
11
11
},
12
- "lint" : {
13
- "rules" : {
14
- "tags" : [" fresh" , " recommended" ]
15
- }
16
- },
12
+ "lint" : { "rules" : { "tags" : [" fresh" , " recommended" ] } },
17
13
"exclude" : [" **/_fresh/*" ],
18
14
"imports" : {
19
15
"$fresh/" : " https://deno.land/x/fresh@1.6.8/" ,
27
23
"$std/" : " https://deno.land/std@0.216.0/" ,
28
24
"$fresh_charts/" : " https://deno.land/x/fresh_charts@0.3.1/"
29
25
},
30
- "compilerOptions" : {
31
- "jsx" : " react-jsx" ,
32
- "jsxImportSource" : " preact"
33
- },
26
+ "compilerOptions" : { "jsx" : " react-jsx" , "jsxImportSource" : " preact" },
34
27
"nodeModulesDir" : true
35
28
}
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import * as $_middleware from "./routes/_middleware.ts";
10
10
import * as $about from "./routes/about.tsx" ;
11
11
import * as $api_joke from "./routes/api/joke.ts" ;
12
12
import * as $api_random_uuid from "./routes/api/random-uuid.ts" ;
13
+ import * as $api_users_id_ from "./routes/api/users/[id].ts" ;
14
+ import * as $api_users_index from "./routes/api/users/index.ts" ;
13
15
import * as $chart from "./routes/chart.tsx" ;
14
16
import * as $countdown from "./routes/countdown.tsx" ;
15
17
import * as $greet_name_ from "./routes/greet/[name].tsx" ;
@@ -35,6 +37,8 @@ const manifest = {
35
37
"./routes/about.tsx" : $about ,
36
38
"./routes/api/joke.ts" : $api_joke ,
37
39
"./routes/api/random-uuid.ts" : $api_random_uuid ,
40
+ "./routes/api/users/[id].ts" : $api_users_id_ ,
41
+ "./routes/api/users/index.ts" : $api_users_index ,
38
42
"./routes/chart.tsx" : $chart ,
39
43
"./routes/countdown.tsx" : $countdown ,
40
44
"./routes/greet/[name].tsx" : $greet_name_ ,
Original file line number Diff line number Diff line change
1
+ import { Handlers } from "$fresh/server.ts" ;
2
+
3
+ export const kv = await Deno . openKv ( ) ;
4
+
5
+ interface User {
6
+ id : string ;
7
+ name : string ;
8
+ }
9
+
10
+ export const handler : Handlers < User | null > = {
11
+ async POST ( req , _ctx ) {
12
+ const user = ( await req . json ( ) ) as User ;
13
+ const userKey = [ "user" , user . id ] ;
14
+ const ok = await kv . atomic ( ) . set ( userKey , user ) . commit ( ) ;
15
+ if ( ! ok ) throw new Error ( "Something went wrong." ) ;
16
+ return new Response ( JSON . stringify ( user ) ) ;
17
+ } ,
18
+ } ;
You can’t perform that action at this time.
0 commit comments