Làm cách nào tôi có thể bật CORS cho trình xử lý còn lại cao bồi? Tôi cố gắng để thêm tùy chọn/2 phương pháp, như thế này:Bật CORS cho API REST Cao bồi
options(Req, State) ->
{[
{<<"access-control-allow-origin">>, <<"*">>},
{<<"access-control-allow-methods">>, <<"GET, OPTIONS">>}
], Req, State}.
nhưng điều này gây ra lỗi như:
Error in process <0.263.0> with exit value: {{case_clause,{[{<<27 bytes>>,<<1 byte>>},{<<28 bytes>>,<<12 bytes>>}],{http_req,#Port<0.2636>,ranch_tcp,keepalive,<0.263.0>,<<7 bytes>>,{1,1},{{127,0,0,1},56522},<<9 bytes>>,undefined,9090,<<8 bytes>>,undefined,<<0 bytes>>,undefined,<<0 bytes>>,[],[{<<4 bytes>>,<<14 bytes>>},{<<10 bytes>>,<<74 bytes>>},{<<6 bytes>>,<<63 bytes>>},{<<15 bytes>>,<<14 bytes>>},{<<15 bytes>>,<<13 bytes>>},{<<6 bytes>>,<<4 bytes>>},{<<29 bytes>>,<<3 bytes>>},{<<30 bytes>>,<<16 bytes>>},{<<10 bytes>>,<<10 bytes>>}],[{<<10 bytes>>,[<<10 bytes>>]}],undefined,[],waiting,undefined,<<0 bytes>>,false,waiting,[],<<0 bytes>>,undefined},undefined...
đâu là sai lầm của tôi?
cảm ơn bạn, đây là đúng! – couchemar
Các tùy chọn/2 sẽ được triển khai ở đâu? Tài liệu không rõ ràng về tệp nào mà chúng tôi nên triển khai. – user859375