@IocBean(singleton = false)
public class CrossProcessor extends AbstractProcessor {
@Override
public void process(ActionContext actionContext) throws Throwable {
actionContext.getResponse().setHeader("Access-Control-Allow-Origin","*");
actionContext.getResponse().setHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");
actionContext.getResponse().setHeader("Access-Control-Allow-Methods","GET, POST, PUT,DELETE,OPTIONS");
doNext(actionContext);
}
}
var chain = {
"default" : {
ps : [
"org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor",
"org.nutz.mvc.impl.processor.EncodingProcessor",
"org.nutz.mvc.impl.processor.ModuleProcessor",
"org.nutz.mvc.impl.processor.ActionFiltersProcessor",
"org.nutz.mvc.impl.processor.AdaptorProcessor",
"org.nutz.mvc.impl.processor.MethodInvokeProcessor",
"ioc:crossProcessor",
"org.nutz.mvc.impl.processor.ViewProcessor"
],
error : 'org.nutz.mvc.impl.processor.FailProcessor'
}
}
我在动作链里面加了改response 的代码,相应 OPTIONS 时就会报错。
有什么办法配置全局的跨域?