app.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. var express = require('express');
  2. var https = require('https');
  3. var http=require('http');
  4. var compression =require('compression');
  5. var fs = require('fs');
  6. app = express();
  7. var ejs = require('ejs');
  8. var cors = require('cors');
  9. var bodyParser = require('body-parser');
  10. var error = require("./models/error.js");
  11. //压缩
  12. app.use(compression());
  13. app.use(bodyParser.json({limit:'50mb'}));
  14. app.use(bodyParser.urlencoded({limit:'50mb',extended:true}));
  15. const corsOptions = {
  16. // origin: ['http://localhost'],
  17. allowedHeaders: ["Content-Type", "Authorization", "Access-Control-Allow-Methods", "Access-Control-Allow-Origin"],
  18. // credentials: true,
  19. // enablePreflight: true
  20. }
  21. app.use(cors(corsOptions));
  22. app.options('*', cors(corsOptions));
  23. /*
  24. API为APP的正式接口及文档目录
  25. */
  26. //
  27. //扫码路由
  28. var scanCode =require("./routes/API/scanCode");
  29. app.use('/S',scanCode);
  30. //小工具入口
  31. var tools =require("./routes/API/tools");
  32. app.use('/tools',tools);
  33. //token校验
  34. var precheck =require("./routes/API/precheck");
  35. app.use('/API/*',precheck);
  36. var preDataQualityCheck =require("./routes/API/preDataQualityCheck");
  37. app.use('/API/*',preDataQualityCheck);
  38. var login = require("./routes/API/login");
  39. app.use('/API/login',login);
  40. var send = require("./routes/API/send");
  41. app.use('/API/send',send);
  42. var regionCode = require("./routes/API/regionCode");
  43. app.use('/API/regionCode',regionCode);
  44. var corporation = require("./routes/API/corporation");
  45. app.use('/API/corporation',corporation);
  46. var typeInfo = require("./routes/API/typeInfo");
  47. app.use('/API/typeInfo',typeInfo);
  48. var plant = require("./routes/API/plant");
  49. app.use('/API/plant',plant);
  50. var plantArea = require("./routes/API/plantArea");
  51. app.use('/API/plantArea',plantArea);
  52. var plantGround = require("./routes/API/plantGround");
  53. app.use('/API/plantGround',plantGround);
  54. var plantInput = require("./routes/API/plantInput");
  55. app.use('/API/plantInput',plantInput);
  56. var plantProcess = require("./routes/API/plantProcess");
  57. app.use('/API/plantProcess',plantProcess);
  58. var plantWarehouse = require("./routes/API/plantWarehouse");
  59. app.use('/API/plantWarehouse',plantWarehouse);
  60. var plantExamine = require("./routes/API/plantExamine");
  61. app.use('/API/plantExamine',plantExamine);
  62. var plantHarvest = require("./routes/API/plantHarvest");
  63. app.use('/API/plantHarvest',plantHarvest);
  64. var plantTran = require("./routes/API/plantTran");
  65. app.use('/API/plantTran',plantTran);
  66. var plantWeather = require("./routes/API/plantWeather");
  67. app.use('/API/plantWeather',plantWeather);
  68. var plantWorker = require("./routes/API/plantWorker");
  69. app.use('/API/plantWorker',plantWorker);
  70. var jobDefination=require("./routes/API/jobDefination");
  71. app.use('/API/jobDefination',jobDefination);
  72. var jobProcess=require("./routes/API/jobProcess");
  73. app.use('/API/jobProcess',jobProcess);
  74. var warehouse=require("./routes/API/warehouse");
  75. app.use('/API/warehouse',warehouse);
  76. var production=require("./routes/API/production");
  77. app.use('/API/production',production);
  78. var productType=require("./routes/API/productType");
  79. app.use('/API/productType',productType);
  80. var productionMaterials=require("./routes/API/productionMaterials");
  81. app.use('/API/productionMaterials',productionMaterials);
  82. var status=require("./routes/API/status");
  83. app.use('/API/status',status);
  84. var businessInfo=require("./routes/API/businessInfo");
  85. app.use('/API/businessInfo',businessInfo);
  86. var processWarehouse=require("./routes/API/processWarehouse");
  87. app.use('/API/processWarehouse',processWarehouse);
  88. var packageCoding=require("./routes/API/packageCoding");
  89. app.use('/API/packageCoding',packageCoding);
  90. var logs=require("./routes/API/logs");
  91. app.use('/API/logs',logs);
  92. var traced=require("./routes/API/traced");
  93. app.use('/API/traced',traced);
  94. var productionInputs=require("./routes/API/productionInputs");
  95. app.use('/API/productionInputs',productionInputs);
  96. var productionProcess=require("./routes/API/productionProcess");
  97. app.use('/API/productionProcess',productionProcess);
  98. var detection=require("./routes/API/detection");
  99. app.use('/API/detection',detection);
  100. var weixin=require("./routes/API/weixin");
  101. app.use('/API/weixin',weixin);
  102. var msg=require("./routes/API/msg");
  103. app.use('/API/msg',msg);
  104. var dictionary=require("./routes/API/dictionary");
  105. app.use('/API/dictionary',dictionary);
  106. var marketAnalysis=require("./routes/API/marketAnalysis");
  107. app.use('/API/marketAnalysis',marketAnalysis);
  108. var station = require("./routes/API/station");
  109. app.use('/API/station',station);
  110. var searchAll = require("./routes/API/searchAll");
  111. app.use('/API/searchAll',searchAll);
  112. var productCode = require("./routes/API/productCode");
  113. app.use('/API/productCode',productCode);
  114. var hikVision = require("./routes/API/hikVision");
  115. app.use('/API/hikVision',hikVision);
  116. var Upload = require("./routes/API/Upload");
  117. app.use('/API/Upload',Upload);
  118. var traceRecall = require("./routes/API/traceRecall");
  119. app.use('/API/traceRecall',traceRecall);
  120. var emergencyPlan = require("./routes/API/emergencyPlan");
  121. app.use('/API/emergencyPlan',emergencyPlan);
  122. var emergencyAffair = require("./routes/API/emergencyAffair");
  123. app.use('/API/emergencyAffair',emergencyAffair);
  124. var zwBanner = require("./routes/API/zwBanner");
  125. app.use('/API/zwBanner',zwBanner);
  126. var zwColumn = require("./routes/API/zwColumn");
  127. app.use('/API/zwColumn',zwColumn);
  128. var zwContent = require("./routes/API/zwContent");
  129. app.use('/API/zwContent',zwContent);
  130. var zwFeedback = require("./routes/API/zwFeedback");
  131. app.use('/API/zwFeedback',zwFeedback);
  132. var zwNewsType = require("./routes/API/zwNewsType");
  133. app.use('/API/zwNewsType',zwNewsType);
  134. var limit = require("./routes/API/limit");
  135. app.use('/API/limit',limit);
  136. var stepDefination = require("./routes/API/stepDefination");
  137. app.use('/API/stepDefination',stepDefination);
  138. var deviceAction = require("./routes/API/deviceAction");
  139. app.use('/API/deviceAction',deviceAction);
  140. var dataQuality = require("./routes/API/dataQuality");
  141. app.use('/API/dataQuality',dataQuality);
  142. var platformApply = require("./routes/API/platformApply");
  143. app.use('/API/platformApply',platformApply);
  144. var productModel = require("./routes/API/productModel");
  145. app.use('/API/productModel',productModel);
  146. var checkResult = require("./routes/API/checkResult");
  147. app.use('/API/checkResult',checkResult);
  148. var checkRule = require("./routes/API/checkRule");
  149. app.use('/API/checkRule',checkRule);
  150. var checkTemplate = require("./routes/API/checkTemplate");
  151. app.use('/API/checkTemplate',checkTemplate);
  152. var checkUploadLogs = require("./routes/API/checkUploadLogs");
  153. app.use('/API/checkUploadLogs',checkUploadLogs);
  154. var loadMonitor = require("./routes/API/loadMonitor");
  155. app.use('/API/loadMonitor',loadMonitor);
  156. var uploadlog = require("./routes/API/uploadlog");
  157. app.use('/API/*',uploadlog);
  158. app.use(function(err, req, res, next) {
  159. // console.error(err);
  160. res.status(500).json(
  161. {
  162. success:99,
  163. message:err.stack,
  164. }
  165. );
  166. });
  167. //指定api的说明文档目录
  168. app.use(express.static('manual'));
  169. app.use('/trans', express.static(__dirname + '/traceCode'));
  170. app.use('/static', express.static(__dirname + '/traceCode'));
  171. //ejs模板引擎
  172. app.engine('html', ejs.renderFile);
  173. app.set("view engine", "html");
  174. //https证书路径设置
  175. var options = {
  176. //正式服务器证书
  177. cert: fs.readFileSync("./cert/fullchain.pem"),
  178. key: fs.readFileSync("./cert/privkey.pem")
  179. };
  180. //安全性设置
  181. app.disable('x-powered-by');
  182. //bodyParser
  183. app.use(bodyParser.json()); // for parsing application/json
  184. app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
  185. //服务器定义
  186. var server = https.createServer(options, app);
  187. // var server = http.createServer(options, app);
  188. //启动服务器
  189. // var port = 8002;
  190. var port = 8089;
  191. server.listen(port, function(){
  192. console.log("server running at https://localhost:"+port);
  193. });