我想尝试一下 Vercel 最近添加的这些新存储功能,但无法让 Postgress 工作。我用的是这个模板。它部署得非常好,但是当我尝试在本地运行它时,我不知道该怎么做。这就是我到目前为止所做的:
npm i现在我得到了包含所有静态内容的页面,但没有来自数据库的数据。当我访问localhost:3000/api/get-users时,我收到以下消息:
"VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found."
看起来是这样get-users.ts的:
import { createPool, sql } from '@vercel/postgres';
async function seed() {
const createTable = await sql`
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email …Run Code Online (Sandbox Code Playgroud) 所以我使用代理进行 API 调用,如下所示:
vue.config.js:
module.exports = {
devServer: {
proxy: 'http://www.pathofexile.com/'
}
}
Run Code Online (Sandbox Code Playgroud)
xxx.vue:
axios.get("http://localhost:8080/api/public-stash-tabs").then..
Run Code Online (Sandbox Code Playgroud)
这有效!现在,当我也想从不同的站点进行 API 调用时,我不知道该怎么做。我想要的是这样的东西:
vue.config.js:
module.exports = {
devServer: {
proxy: {
'http://localhost:8080/one/': {
target: 'http://www.pathofexile.com/',
changeOrigin: true
},
'http://localhost:8080/two/': {
target: 'https://api.poe.watch/',
changeOrigin: true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
xxx.vue:
axios.get("http://localhost:8080/one/api/public-stash-tabs").then..
axios.get("http://localhost:8080/two/id").then..
Run Code Online (Sandbox Code Playgroud)
但似乎什么也没发生,我收到 404 错误,因为它尝试从 http://localhost:8080/api/public-stash-tabs获取某些内容
我是否走在正确的轨道上,我是否错过了一些东西?或者这不是要走的路?