我的 API 在一个测功机上,我的前端在另一个测功机上。
我不确定如何访问 api dyno。
示例:
web: yarn --cwd web start -p $PORT
api: bundle exec rails s -p 3001
然后是一个代理:
const apiProxy = createProxyMiddleware({
target: 'http://127.0.0.1:3001',
changeOrigin: true,
pathRewrite: { [`^/api/graphql`]: '' },
secure: false,
});
export default function (req, res) {
apiProxy(req, res, (result) => {
if (result instanceof Error) {
throw result;
}
throw new Error(`Request '${req.url}' is not proxied! We should never reach here!`);
});
};
不过似乎没有这么简单。
答案 0 :(得分:0)
在 Web Dyno 上部署 API 组件后,您应该使用 Heroku 分配的主机,例如 myapi.herokuapp.com
。
要调用的端点是 https://myapi.herokuapp.com