大佬教程收集整理的这篇文章主要介绍了javascript – hapi.js Cors Pre-flight不返回Access-Control-Allow-Origin标头,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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.
这是hapi js路由处理程序
server.route({ path: '/uploadbookimg',method: 'POST',config: { cors : true,payload: { output: 'stream',parse: true,allow: 'multipart/form-data' },handler: require('./books/webbookimgupload'),} });
在我的理解中,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: no-cache vary: accept-encoding Date: Wed,27 Apr 2016 07:25:33 GMT Connection: keep-alive Transfer-Encoding: chunked **request Headers** view parsed OPTIONS /uploadbookimg http/1.1 Host: localhost:3000 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Access-Control-request-Method: POST Origin: http://localhost:4200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/50.0.2661.87 Safari/537.36 Access-Control-request-Headers: accept,cache-control,content-type Accept: */* Referer: http://localhost:4200/books/upload Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8
提前致谢
[“接受”,“授权”,“内容类型”,“if-none-match”,“Origin”]
See the cors
option section in the API docs under route options:
您的问题是Dropzone发送了几个标题以及不在此列表中的文件上载:
> x-requested-with(不在上面的标题中,但是是为我发送的)
>缓存控制
您有两种方法可以使工作正常,您需要在服务器或客户端上进行更改:
选项1 – 将额外标题列入白名单:
server.route({ config: { cors: { origin: ['*'],additionalHeaders: ['cache-control','x-requested-with'] } },path: '/upload',handler: function (request,reply) { ... } });
选项2 – 告诉dropzone不发送那些额外的标题
尚未通过他们的配置,但有一个待定的PR允许它:https://github.com/enyo/dropzone/pull/685
以上是大佬教程为你收集整理的javascript – hapi.js Cors Pre-flight不返回Access-Control-Allow-Origin标头全部内容,希望文章能够帮你解决javascript – hapi.js Cors Pre-flight不返回Access-Control-Allow-Origin标头所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。