0
이것은 주로 로컬에서 서비스를 개발하는 데 사용됩니다.405 방법은 Restify 및 CORS에서 DELETE를 사용하여 허용되지 않습니다.
Restify 및 CORS를 사용하여 DELETE 요청이있는 405 method not allowed
이 표시됩니다. 나는 뭔가를 간과해야한다고 생각합니다. 내가 잘못하고있는 것을 지적하기 위해 신선한 눈으로 정말로 감사 할 것입니다.
약 restify-cors-middleware
에 대해 알고 있지만 문서화되지 않았기 때문에 사용하지 않고 올바르게 구성 할 수 없었습니다.
대신 Restify에 대한 CORS 구성을 구현했습니다. GET 및 POST에서는 작동하지만 DELETE에서는 작동하지 않습니다.
// allows localhost to work
if (process.env.DEV === 'true') {
app.pre((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, Content-Disposition, Origin, X-Requested-With');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Methods', 'DELETE, GET, POST, OPTIONS, PUT');
res.header('access-control-max-age', 86400);
return next();
});
app.opts('/.*/', (req, res, next) => {
res.send(200);
return next();
});
}
옵션 프리 플라이트 :
요청
URL: http://localhost:8000/f388798f20e0d496023812a05109ea5276d2eb3d41f8eb5b58c9d43da9b7a001-leWWTe
Request Method:OPTIONS
Status Code:200 OK
Remote Address:[::1]:8000
Referrer Policy:no-referrer-when-downgrade
응답 헤더
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, Content-Disposition, Origin, X-Requested-With
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: DELETE, GET, POST, OPTIONS, PUT
access-control-max-age: 86400
Date: Tue, 10 Oct 2017 01:04:57 GMT
Connection: keep-alive
Transfer-Encoding: chunked
요청 헤더
(210)삭제 요청 :
요청
URL: http://localhost:8000/f388798f20e0d496023812a05109ea5276d2eb3d41f8eb5b58c9d43da9b7a001-leWWTe
Request Method:DELETE
Status Code:405 Method Not Allowed
Remote Address:[::1]:8000
Referrer Policy:no-referrer-when-downgrade
응답 헤더
HTTP/1.1 405 Method Not Allowed
Server: Planet Timelapse
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, Content-Disposition, Origin, X-Requested-With
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: DELETE, GET, POST, OPTIONS, PUT
access-control-max-age: 86400
Allow: OPTIONS
Content-Type: application/json
Content-Length: 61
Date: Tue, 10 Oct 2017 01:04:57 GMT
Connection: keep-alive
요청 헤더
DELETE /f388798f20e0d496023812a05109ea5276d2eb3d41f8eb5b58c9d43da9b7a001-leWWTe HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
accept: application/json
Origin: http://localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Referer: http://localhost:3000/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8