我正在尝试将 CORS 标头添加到传入的请求中,但我注意到这app.response.headers
是一个不可变的映射,app.request.response
即使它出现在文档示例中也不存在。因此,对于OPTIONS
我正在使用新Shelf
响应回复的请求,但我找不到将任何新标头添加到实际请求的响应中的方法。有任何想法吗?
@app.Interceptor(r"/api/.*", chainIdx: 1)
corsInterceptor() {
if (app.request.method == "OPTIONS") {
var response = new shelf.Response.ok("", headers: HEADERS);
app.chain.interrupt(statusCode: HttpStatus.OK, responseValue: response);
} else {
// app.request.response is not available
app.request.response.headers.add('Access-Control-Allow-Origin', '*');
app.chain.next();
}
}