-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from fastrodev/store
Store
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import fastro, { Context, HttpRequest } from "@app/mod.ts"; | ||
|
||
const f = new fastro(); | ||
|
||
// set default value for the store | ||
f.store.set("hello", "hello world"); | ||
|
||
// update default value | ||
f.post( | ||
"/", | ||
(_req: HttpRequest, ctx: Context) => { | ||
ctx.store.set("hello", "hello world v2"); | ||
return ctx.send("Helo world", 200); | ||
}, | ||
); | ||
|
||
// update default value with TTL | ||
f.post( | ||
"/ttl", | ||
(_req: HttpRequest, ctx: Context) => { | ||
ctx.store.set("hello", "world", 1000); | ||
return ctx.send("ttl", 200); | ||
}, | ||
); | ||
|
||
// save store to github | ||
f.post( | ||
"/commit", | ||
async (_req: HttpRequest, ctx: Context) => { | ||
await ctx.store.commit(); | ||
return ctx.send("commit", 200); | ||
}, | ||
); | ||
|
||
// destroy file | ||
f.post( | ||
"/destroy", | ||
async (_req: HttpRequest, ctx: Context) => { | ||
await ctx.store.destroy(); | ||
return ctx.send("destroy", 200); | ||
}, | ||
); | ||
|
||
// get the value | ||
f.get( | ||
"/", | ||
async (_req: HttpRequest, ctx: Context) => { | ||
const res = await ctx.store.get("hello"); | ||
return Response.json({ value: res }); | ||
}, | ||
); | ||
|
||
await f.serve(); |