Tag: her

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

我在node.js的快速框架上编写了一个REST API,这个框架适用于Chrome中js控制台的请求和URL栏等等。我现在试图让它适用于来自另一个应用程序的请求域(CORS)。 第一个由javascript前端自动创build的请求是/ api / search?uri =,并且在“预检”选项请求中显示为失败。 在我的快速应用程序中,我添加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(); } }; 和: 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 […]