Vercel postgres 存储 + 下一个有 CORS 问题的项目

问题描述 投票:0回答:0

我有兴趣尝试使用 Vercel 引入的最新存储功能,但我无法使用 Postgres 功能。我不确定这是如何工作的。

我已经关注了他们的文档:quickstart。这是我到目前为止所做的:

  • 创建一个数据库并链接到我的项目+我已经通过vercel平台直接向其中添加了一个简单的表。
  • 运行
    vercel env pull .env.development.local
    以检索由 vercel
  • 创建的环境

我在我的一个组件中得到了它:

import { createClient, createPool, db, sql } from "@vercel/postgres"

async function test() {
  console.log(process.env.POSTGRES_URL)

  const db = createPool()

  const { rows: users } = await db.query("SELECT * FROM users")
}

当代码被执行时,无论是在本地还是直接在部署的应用程序上,我都会遇到 cors 错误:

Access to fetch at '{POSTGRES_HOST}' from origin 'https://movielog-pied.vercel.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

POSTGRES_HOST 是 vercel 给出的环境。我试图在所有方法上添加 cors 权限,但没有成功。

还有一些关于如何连接的文档,但它对我不起作用。他们的例子是:

*

我遇到了那个
issue

postgresql vercel next
© www.soinside.com 2019 - 2024. All rights reserved.