var http = require('http'); var https = require('https'); var path = require('path'); var fs = require('fs'); var options = { key: fs.readFileSync(''), cert: fs.readFileSync('') }; var express = require('express'); var app = express(); app.set('trust proxy', 'loopback'); app.use(express.static(path.join(__dirname, 'public'))); require('./config/routes')(app); app.use(function (req, res, next) { var err = new Error('Not Found'); res.json({ errormsg: err.status + ' Not Found ' }); }); app.use(function (req, res, next) { res.status(err.status || 500); res.json({ errormsg: err.status }) }) http.createServer(app).listen(80); https.createServer(options, app).listen(443); console.log('80') console.log('443')
补充:require('./config/routes')(app); 报错,应该没用,注释掉可以正常使用
https://segmentfault.com/a/1190000008398220
https://www.gaoshilei.com/2017/10/30/hexo-init/