resource.cloudflare.ts 701 B

12345678910111213141516171819202122
  1. import { env } from "cloudflare:workers"
  2. export { waitUntil } from "cloudflare:workers"
  3. export const Resource = new Proxy(
  4. {},
  5. {
  6. get(_target, prop: string) {
  7. console.log(`111 ${prop}`)
  8. if (`SST_RESOURCE_${prop}` in env) {
  9. console.log(`222 ${prop}`)
  10. // @ts-expect-error
  11. const value = env[`SST_RESOURCE_${prop}`]
  12. console.log(`333 ${value}`)
  13. return typeof value === "string" ? JSON.parse(value) : value
  14. } else if (prop === "App") {
  15. // @ts-expect-error
  16. return JSON.parse(env.SST_RESOURCE_App)
  17. }
  18. throw new Error(`"${prop}" is not linked in your sst.config.ts (cloudflare)`)
  19. },
  20. },
  21. ) as Record<string, any>