【问题标题】:Remix.run + Cloudflare worker environmental variablesRemix.run + Cloudflare worker 环境变量
【发布时间】:2023-01-14 06:34:02
【问题描述】:

我正在尝试与 Cloudflare 工作人员一起运行 Remix.run。我如何在 Remix.run 数据加载器函数中访问与 Cloudflare 数据持久性服务(例如 D1)相关的环境变量?

我已经通过wrangler.toml“绑定”了工作人员,并且可以通过 wrangler 访问该服务。

[[ d1_databases ]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "Example"
database_id = "123-456-789"

我可以使用.env.vars从全局范围访问其他环境变量,但似乎无法访问DB

【问题讨论】:

    标签: cloudflare cloudflare-workers remix.run


    【解决方案1】:

    在 Cloudflare Workers 中,环境变量暴露在 global 对象上。我建议将它们全部大写。

    declare var DATABASE_ID: string
    console.log(DATABASE_ID)
    

    【讨论】:

    【解决方案2】:

    DB 绑定使用新的 module syntax 为我工作。请注意,这与 the old service worker syntax 不同。 Durable objects require module Workers - 也许新的 D1 也是如此?

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 2014-09-30
      • 2020-12-07
      • 1970-01-01
      相关资源
      最近更新 更多