root 1 year ago
parent
commit
23d2eedfe3
1 changed files with 16 additions and 15 deletions
  1. 16 15
      app.js

+ 16 - 15
app.js

@@ -15,25 +15,26 @@ app.use(bodyParser.urlencoded({ extended: true, limit: '3mb' }));
 app.use(bodyParser.json({ limit: '3mb' }));
 
 //暂时全跨域
-app.use(function(req, res, next) {
+app.use(function (req, res, next) {
     ///var allowedOrigins = [config.local.origin,'http://cocorobo.hk','http://www.cocorobo.hk','https://cocorobo.hk','http://cloud.cocorobo.hk','https://cloud.cocorobo.hk'];
     var origin = req.headers.origin || "*";
     //if(allowedOrigins.indexOf(origin) > -1){
-    res.setHeader('Access-Control-Allow-Origin', origin);
+    //res.setHeader('Access-Control-Allow-Origin', origin);
+    res.setHeader('Access-Control-Allow-Origin', "https://cxcy.ssti.net.cn");
     //}
     res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
-    res.header('Access-Control-Allow-Credentials', true);
+    //res.header('Access-Control-Allow-Credentials', true);
     //修改程序信息与版本
     res.header('X-Powered-By', ' 3.2.1')
-        //内容类型:如果是post请求必须指定这个属性
+    //内容类型:如果是post请求必须指定这个属性
     res.header('Content-Type', 'application/json;charset=utf-8')
     next();
 });
 
 //设置返回结果
-app.use((req,res,next)=>{
-    res.Back = (code,msg,data)=>res.send({status:code,msg:msg,data:data});
+app.use((req, res, next) => {
+    res.Back = (code, msg, data) => res.send({ status: code, msg: msg, data: data });
     next();
 })
 
@@ -48,17 +49,17 @@ app.use(cors({
 app.use('/api', edurouter);
 // app.use('/game', game);
 
-app.all('/download', function(req, res, next) {
+app.all('/download', function (req, res, next) {
     //req.body.url = "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/%E4%B8%8B%E8%BD%BD%20%284%29.doc";
     request({
-            url: req.body.url,
-            method: "GET",
-            encoding: null,
-            headers: {
-                'Accept-Encoding': 'gzip, deflate'
-            }
-        },
-        function(error, response, body) {
+        url: req.body.url,
+        method: "GET",
+        encoding: null,
+        headers: {
+            'Accept-Encoding': 'gzip, deflate'
+        }
+    },
+        function (error, response, body) {
             if (!error && response.statusCode == 200) {
                 res.setHeader('Content-Type', 'application/force-download');
                 res.setHeader('Content-Disposition', 'attachment; filename=' + path.basename(req.body.url));