小编kwe*_*360的帖子

hapi.js Cors Pre-flight不返回Access-Control-Allow-Origin标头

我使用(Dropzone js)上传了ajax文件.它将文件发送到我的hapi服务器.我意识到浏览器发送了一个PREFLIGHT OPTIONS METHOD.但我的hapi服务器似乎没有发送正确的响应标头所以我在chrome上遇到错误.这是我得到的错误

XMLHttpRequest cannot load http://localhost:3000/uploadbookimg. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

这是hapi js路由处理程序

server.route({
        path: '/uploadbookimg',
        method: 'POST',
        config: {
            cors : true,
            payload: {
                output: 'stream',
                parse: true,
                allow: 'multipart/form-data'
            },
        handler: require('./books/webbookimgupload'),
        }
    });
Run Code Online (Sandbox Code Playgroud)

根据我的理解,hapi js应该从Pre-fight(OPTIONS)请求发送所有cors头.不明白为什么不是

来自Chrome的网络请求/响应

**General**
Request Method:OPTIONS
Status Code:200 OK
Remote Address:127.0.0.1:3000

**Response Headers**
view parsed
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
cache-control: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js cors dropzone.js hapijs

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

cors ×1

dropzone.js ×1

hapijs ×1

javascript ×1

node.js ×1