var express = require('express'); var https = require('https'); var http=require('http'); var compression =require('compression'); var fs = require('fs'); app = express(); var ejs = require('ejs'); var cors = require('cors'); var bodyParser = require('body-parser'); var error = require("./models/error.js"); //压缩 app.use(compression()); app.use(bodyParser.json({limit:'50mb'})); app.use(bodyParser.urlencoded({limit:'50mb',extended:true})); const corsOptions = { // origin: ['http://localhost'], allowedHeaders: ["Content-Type", "Authorization", "Access-Control-Allow-Methods", "Access-Control-Allow-Origin"], // credentials: true, // enablePreflight: true } app.use(cors(corsOptions)); app.options('*', cors(corsOptions)); /* API为APP的正式接口及文档目录 */ // //扫码路由 var scanCode =require("./routes/API/scanCode"); app.use('/S',scanCode); //小工具入口 var tools =require("./routes/API/tools"); app.use('/tools',tools); //token校验 var precheck =require("./routes/API/precheck"); app.use('/API/*',precheck); var preDataQualityCheck =require("./routes/API/preDataQualityCheck"); app.use('/API/*',preDataQualityCheck); var login = require("./routes/API/login"); app.use('/API/login',login); var send = require("./routes/API/send"); app.use('/API/send',send); var regionCode = require("./routes/API/regionCode"); app.use('/API/regionCode',regionCode); var corporation = require("./routes/API/corporation"); app.use('/API/corporation',corporation); var typeInfo = require("./routes/API/typeInfo"); app.use('/API/typeInfo',typeInfo); var plant = require("./routes/API/plant"); app.use('/API/plant',plant); var plantArea = require("./routes/API/plantArea"); app.use('/API/plantArea',plantArea); var plantGround = require("./routes/API/plantGround"); app.use('/API/plantGround',plantGround); var plantInput = require("./routes/API/plantInput"); app.use('/API/plantInput',plantInput); var plantProcess = require("./routes/API/plantProcess"); app.use('/API/plantProcess',plantProcess); var plantWarehouse = require("./routes/API/plantWarehouse"); app.use('/API/plantWarehouse',plantWarehouse); var plantExamine = require("./routes/API/plantExamine"); app.use('/API/plantExamine',plantExamine); var plantHarvest = require("./routes/API/plantHarvest"); app.use('/API/plantHarvest',plantHarvest); var plantTran = require("./routes/API/plantTran"); app.use('/API/plantTran',plantTran); var plantWeather = require("./routes/API/plantWeather"); app.use('/API/plantWeather',plantWeather); var plantWorker = require("./routes/API/plantWorker"); app.use('/API/plantWorker',plantWorker); var jobDefination=require("./routes/API/jobDefination"); app.use('/API/jobDefination',jobDefination); var jobProcess=require("./routes/API/jobProcess"); app.use('/API/jobProcess',jobProcess); var warehouse=require("./routes/API/warehouse"); app.use('/API/warehouse',warehouse); var production=require("./routes/API/production"); app.use('/API/production',production); var productType=require("./routes/API/productType"); app.use('/API/productType',productType); var productionMaterials=require("./routes/API/productionMaterials"); app.use('/API/productionMaterials',productionMaterials); var status=require("./routes/API/status"); app.use('/API/status',status); var businessInfo=require("./routes/API/businessInfo"); app.use('/API/businessInfo',businessInfo); var processWarehouse=require("./routes/API/processWarehouse"); app.use('/API/processWarehouse',processWarehouse); var packageCoding=require("./routes/API/packageCoding"); app.use('/API/packageCoding',packageCoding); var logs=require("./routes/API/logs"); app.use('/API/logs',logs); var traced=require("./routes/API/traced"); app.use('/API/traced',traced); var productionInputs=require("./routes/API/productionInputs"); app.use('/API/productionInputs',productionInputs); var productionProcess=require("./routes/API/productionProcess"); app.use('/API/productionProcess',productionProcess); var detection=require("./routes/API/detection"); app.use('/API/detection',detection); var weixin=require("./routes/API/weixin"); app.use('/API/weixin',weixin); var msg=require("./routes/API/msg"); app.use('/API/msg',msg); var dictionary=require("./routes/API/dictionary"); app.use('/API/dictionary',dictionary); var marketAnalysis=require("./routes/API/marketAnalysis"); app.use('/API/marketAnalysis',marketAnalysis); var station = require("./routes/API/station"); app.use('/API/station',station); var searchAll = require("./routes/API/searchAll"); app.use('/API/searchAll',searchAll); var productCode = require("./routes/API/productCode"); app.use('/API/productCode',productCode); var hikVision = require("./routes/API/hikVision"); app.use('/API/hikVision',hikVision); var Upload = require("./routes/API/Upload"); app.use('/API/Upload',Upload); var traceRecall = require("./routes/API/traceRecall"); app.use('/API/traceRecall',traceRecall); var emergencyPlan = require("./routes/API/emergencyPlan"); app.use('/API/emergencyPlan',emergencyPlan); var emergencyAffair = require("./routes/API/emergencyAffair"); app.use('/API/emergencyAffair',emergencyAffair); var zwBanner = require("./routes/API/zwBanner"); app.use('/API/zwBanner',zwBanner); var zwColumn = require("./routes/API/zwColumn"); app.use('/API/zwColumn',zwColumn); var zwContent = require("./routes/API/zwContent"); app.use('/API/zwContent',zwContent); var zwFeedback = require("./routes/API/zwFeedback"); app.use('/API/zwFeedback',zwFeedback); var zwNewsType = require("./routes/API/zwNewsType"); app.use('/API/zwNewsType',zwNewsType); var limit = require("./routes/API/limit"); app.use('/API/limit',limit); var stepDefination = require("./routes/API/stepDefination"); app.use('/API/stepDefination',stepDefination); var deviceAction = require("./routes/API/deviceAction"); app.use('/API/deviceAction',deviceAction); var dataQuality = require("./routes/API/dataQuality"); app.use('/API/dataQuality',dataQuality); var platformApply = require("./routes/API/platformApply"); app.use('/API/platformApply',platformApply); var productModel = require("./routes/API/productModel"); app.use('/API/productModel',productModel); var checkResult = require("./routes/API/checkResult"); app.use('/API/checkResult',checkResult); var checkRule = require("./routes/API/checkRule"); app.use('/API/checkRule',checkRule); var checkTemplate = require("./routes/API/checkTemplate"); app.use('/API/checkTemplate',checkTemplate); var checkUploadLogs = require("./routes/API/checkUploadLogs"); app.use('/API/checkUploadLogs',checkUploadLogs); var loadMonitor = require("./routes/API/loadMonitor"); app.use('/API/loadMonitor',loadMonitor); var uploadlog = require("./routes/API/uploadlog"); app.use('/API/*',uploadlog); app.use(function(err, req, res, next) { // console.error(err); res.status(500).json( { success:99, message:err.stack, } ); }); //指定api的说明文档目录 app.use(express.static('manual')); app.use('/trans', express.static(__dirname + '/traceCode')); app.use('/static', express.static(__dirname + '/traceCode')); //ejs模板引擎 app.engine('html', ejs.renderFile); app.set("view engine", "html"); //https证书路径设置 var options = { //正式服务器证书 cert: fs.readFileSync("./cert/fullchain.pem"), key: fs.readFileSync("./cert/privkey.pem") }; //安全性设置 app.disable('x-powered-by'); //bodyParser app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded //服务器定义 var server = https.createServer(options, app); // var server = http.createServer(options, app); //启动服务器 // var port = 8002; var port = 8089; server.listen(port, function(){ console.log("server running at https://localhost:"+port); });