小编Jam*_*som的帖子

允许对Heroku上的Express/Node.js应用程序发出CORS REST请求

我已经写在快递框架REST API为从Chrome中的JS控制台,地址栏等要求,现在我试图得到它的工作从另一个应用程序请求node.js的工作,在不同的域(CORS).

由javascript前端自动生成的第一个请求是/ api/search?uri =,并且似乎在"预检"OPTIONS请求中失败.

在我的快递应用程序中,我正在添加CORS标头,使用:

var allowCrossDomain = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');

    // intercept OPTIONS method
    if ('OPTIONS' == req.method) {
      res.send(200);
    }
    else {
      next();
    }
};
Run Code Online (Sandbox Code Playgroud)

和:

app.configure(function () {
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(allowCrossDomain);
  app.use(express.static(path.join(application_root, "public")));
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
Run Code Online (Sandbox Code Playgroud)

在Chrome控制台中,我得到以下标题:

请求网址:http://furious-night-5419.herokuapp.com/api/search?uri = http%3A%2F%2Flocalhost%3A5000%2Fcollections%2F1%2Fdocuments%2F1

请求方法:选项

状态代码:200 OK

请求标题

Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:origin, x-annotator-auth-token, accept
Access-Control-Request-Method:GET
Connection:keep-alive
Host:furious-night-5419.herokuapp.com
Origin:http://localhost:5000
Referer:http://localhost:5000/collections/1/documents/1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS …
Run Code Online (Sandbox Code Playgroud)

rest heroku node.js cors express

87
推荐指数
2
解决办法
7万
查看次数

Rails/Heroku/Assets不包括在内

我有一个使用redactor(一个所见即所得编辑器)的应用程序,它在本地完美运行,当我上传它时也可以工作,除了配置文件,它位于子文件夹中,当推送到Heroku时做任何事情.我试过预编译,使用:

RAILS_ENV=production bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

我有config.assets.enabled = false

无法在Heroku上运行的config.js文件作为redactor-rails/config包含在application.js中

可能是什么问题?

assets ruby-on-rails heroku asset-pipeline

2
推荐指数
1
解决办法
791
查看次数

标签 统计

heroku ×2

asset-pipeline ×1

assets ×1

cors ×1

express ×1

node.js ×1

rest ×1

ruby-on-rails ×1