node.js - 使用 Heroku 在另一个测功机上代理 API
问题描述
我的 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!`);
});
};
不过,这似乎不是那么直截了当。
解决方案
一旦 API 组件部署在 Web Dyno 上,您应该使用 Heroku 分配的主机,例如myapi.herokuapp.com
.
然后调用的端点是https://myapi.herokuapp.com
推荐阅读
- python - Django FilteredRelation 不适用于 GenericRelation
- r - 有没有人在 R 中尝试过 Piwik PRO api?
- python - Windows 10 操作系统中的 Scikit-bio 安装错误,“错误:scikit-bio 构建轮失败”
- amazon-web-services - 将固定数据字段添加到 Salesforce -> Appflow -> Eventbridge 配置
- fortran - MPI_finalize 是否释放内存?
- android - android应用程序类中的空上下文异常
- python-3.x - 密码没有得到散列django rest框架
- python - Python:预先初始化并将数据附加到未知长度的 3d numpy 数组
- javascript - Prop 到 React 中的类变量解构
- java - 如何从 java.util.Properties 获取默认值