I have ajax file upload using (Dropzone js). which sends the file to my hapi server. I realized that the browser sends SPECIFICATIONS OF PRELIMINARY OPTIONS. but my hapi server doesn't seem to send the correct response headers, so I get errors on chrome. here is the error i get 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.
this is the hapi js route handler
server.route({ path: '/uploadbookimg', method: 'POST', config: { cors : true, payload: { output: 'stream', parse: true, allow: 'multipart/form-data' }, handler: require('./books/webbookimgupload'), } });
In my understanding, hapi js should send all the cors headers from the Pre-fight (OPTIONS) request. I can not understand why it is not
Network request / response from 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
Thanks in advance
kweku360
source share