import type { NextRequest } from "next/server";
import { getRequestContext } from "@cloudflare/next-on-pages";
export const runtime = "edge";
export async function GET(request: NextRequest) {
const context = getRequestContext();
let id = context.env.MY_DURABLE_OBJECT.idFromName(
new URL(request.url).pathname
);
const stub = context.env.MY_DURABLE_OBJECT.get(id);
console.log("env", context.env); // env has my DO in it
console.log({ id, stub }); // id and stub are undefined
// what should be here?
// i tried passing "request" but it says it cant get a url from it so i just put a url that works for now
const x = await stub.fetch("http://localhost/whatever");
const text = await x.text();
return Response.json({ text });
}
import type { NextRequest } from "next/server";
import { getRequestContext } from "@cloudflare/next-on-pages";
export const runtime = "edge";
export async function GET(request: NextRequest) {
const context = getRequestContext();
let id = context.env.MY_DURABLE_OBJECT.idFromName(
new URL(request.url).pathname
);
const stub = context.env.MY_DURABLE_OBJECT.get(id);
console.log("env", context.env); // env has my DO in it
console.log({ id, stub }); // id and stub are undefined
// what should be here?
// i tried passing "request" but it says it cant get a url from it so i just put a url that works for now
const x = await stub.fetch("http://localhost/whatever");
const text = await x.text();
return Response.json({ text });
}