node.js - heroku 用 fastify 支持 nodejs 吗?
问题描述
我试图用 fastify 打我的 heroku nodejs 应用程序,而不是用我的 netifly react 应用程序表达,但我得到一个 CORS 错误。
一直在尝试安装一些软件包,但没有运气。
有没有人遇到过这种问题?netlify打heroku节点api?
编辑:
// create the server
const fastify = Fastify({
ignoreTrailingSlash: true,
trustProxy: true,
logger: {
genReqId: createRequestId,
level: "info"
}
});
// Use Header
fastify.register(fastifyCors, {
// put your options here
origin: "*",
methods: "GET,HEAD,OPTIONS,POST,PUT",
allowedHeaders: "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers",
credentials: true,
preflightContinue: true,
maxAge: 86400
})
尝试在 Heroku 中使用 fastify 访问 nodejs 时,netlify react 应用程序出错:
从源“ https://qwerty.netlify.app ”访问“ https://asd.herokuapp.com/api/images_type/slider ”的 XMLHttpRequest已被 CORS 策略阻止:否 'Access-Control-Allow-Origin ' 请求的资源上存在标头。块引用
此外,如果我想点击https://asd.herokuapp.com/api/images_type/slider应该给我一个数组但在 heroku 应用程序上抛出一个错误,但部署成功。所以我不知道
解决方案
推荐阅读
- html - 如何在 Angular 中使用模板驱动的表单验证数字字段?
- nginx - https://[ip address] 到域重定向 nginx
- boost - CMake MinGW 无法链接提升
- thingsboard - 如何让每个参数出现在表格行中?
- c++ - 别名、模板化函数和专业化
- lwm2m - 找不到有关 lwm2m / wakaama 的文档
- docker - 即使安装了 Ansible 也无法导入 docker
- azure-data-explorer - Kusto 显示功能 | 显示有关功能的信息
- google-bigquery - 可以使用气流 BigQueryOperator 制作 DDL bigquery 语句吗?
- github - 创建一个包含提交的查询