【问题标题】:Sails.JS image uploading not working in production? Works in development stagingSails.JS 图片上传在生产中不起作用?工作在开发阶段
【发布时间】:2018-08-23 07:37:18
【问题描述】:

我使用 Vue.JS 作为前端,使用 Sails.JS 作为后端。

除了图片上传之外,一切都在我的本地机器和生产环境中运行。

我收到以下错误:

POST http://{mysailsdomain}/api/v1/upload 413 (Request Entity Too Large)

Failed To Load http://{mysailsdomain}/api/v1/upload: No 'Access-Control-Origin' header is present on the requested resource. Origin 'http://{myvuedomain}' is therfore not allowed access. The response had HTTP status code 413.

Uncaught (in promise) B {url: "http://{mysailsdomain}/api/v1/upload", ok: false, status: 0, statusText: "", headers: U, …}

Cross-Origin Read Blocking (CORB) blocked cross-origin response http://{mysailsdomain}/api/v1/upload with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

我的config/security.js

cors: {
    allRoutes: true,
    allowOrigins: '*',
    allowCredentials: false,
  },

我用谷歌搜索了这个错误,有人建议将此代码添加到我的config/http.js

bodyParser: (function () {
      var opts = {limit:'50mb'};
      var fn;

      // Default to built-in bodyParser:
      fn = require('skipper');
      return fn(opts);

    })

我添加了代码,但问题仍然存在。

这是我的production.js

onlyAllowOrigins: [
   'http://{myvuejsdashboard}',
   'http://{myvuejsapp}'
 ]

我什至尝试将所有onlyAllowOrigins 注释掉,但仍然没有成功。

我正在使用 Sails v1.0.2。

【问题讨论】:

    标签: ubuntu nginx vue.js sails.js digital-ocean


    【解决方案1】:

    您的生产环境设置是什么?它是否在代理服务器ngnix后面,看起来您的代理服务器正在拒绝上传,因为代理服务器上设置了限制。

    如果您使用的是 ngnix,您可以在 ngnix 配置中将 client_max_body_size 设置为 50MB,然后重新启动您的 ngnix 以重新加载配置。

    这应该可以解决您的第一个问题。 [ 413(请求实体太大)]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      相关资源
      最近更新 更多