首页 > 解决方案 > 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 应用程序上抛出一个错误,但部署成功。所以我不知道

标签: node.jsreactjsherokunetlifyfastify

解决方案


推荐阅读