瀏覽代碼

add options

maguohua1 6 年之前
父節點
當前提交
374a711f4f
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      app.js

+ 6 - 2
app.js

@@ -17,10 +17,14 @@ const app = express();
 app.all('*', (req, res, next) => {
 	res.header("Access-Control-Allow-Origin", req.headers.origin || req.headers.referer || '*');
 	res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
-	res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE");
+	res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
   res.header("Access-Control-Allow-Credentials", true); //可以带cookies
 	res.header("X-Powered-By", 'Express');
-	next();
+	if (req.method == 'OPTIONS') {
+  	res.sendStatus(200);
+	} else {
+    next();
+	}
 });
 
 // app.use(Statistic.apiRecord)