blob: 4f42236814e656d9662e8d12adae338106fc8707 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import type { APIRoute } from 'astro';
interface Env {
COUNTER_DO: DurableObjectNamespace;
}
export const GET: APIRoute = async ({ locals }) => {
const env = locals.runtime.env as Env;
const id = env.COUNTER_DO.idFromName('counter');
const stub = env.COUNTER_DO.get(id);
const response = await stub.fetch('https://counter.do/get');
return response;
};
export const POST: APIRoute = async ({ locals }) => {
const env = locals.runtime.env as Env;
const id = env.COUNTER_DO.idFromName('counter');
const stub = env.COUNTER_DO.get(id);
const response = await stub.fetch('https://counter.do/increment');
return response;
};
|