mirror of
https://github.com/zyllian/webdog.git
synced 2025-05-10 10:36:39 -07:00
add global pet counter to site :3
This commit is contained in:
parent
0e444ec503
commit
29dcdc85cb
14 changed files with 3677 additions and 0 deletions
33
cf/src/index.ts
Normal file
33
cf/src/index.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Welcome to Cloudflare Workers! This is your first worker.
|
||||
*
|
||||
* - Run `npm run dev` in your terminal to start a development server
|
||||
* - Open a browser tab at http://localhost:8787/ to see your worker in action
|
||||
* - Run `npm run deploy` to publish your worker
|
||||
*
|
||||
* Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
|
||||
* `Env` object can be regenerated with `npm run cf-typegen`.
|
||||
*
|
||||
* Learn more at https://developers.cloudflare.com/workers/
|
||||
*/
|
||||
|
||||
import { Hono } from 'hono';
|
||||
import { cors } from 'hono/cors';
|
||||
|
||||
const app = new Hono<{ Bindings: Env }>();
|
||||
|
||||
app.use('/api/*', cors());
|
||||
|
||||
app.get('/api/pet', async (c) => {
|
||||
return c.json({
|
||||
count: (await c.env.DB.prepare('SELECT count FROM pets').first())!.count,
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/pet', async (c) => {
|
||||
return c.json({
|
||||
count: (await c.env.DB.prepare('UPDATE pets SET count = count + 1 RETURNING count').first())!.count,
|
||||
});
|
||||
});
|
||||
|
||||
export default app satisfies ExportedHandler<Env>;
|
Loading…
Add table
Add a link
Reference in a new issue