express 后台搭建

2019-03-19  本文已影响0人  2359634711

0x01 express 快速搭建

原文链接

1. 安装express-generator
$ npm install express-generator -g
2. 目录结构
image.png
app.use(express.static(path.join(__dirname, 'public')));
3. 搭建https
var https = require('https');
var fs = require('fs');

/*
* 设置https文件
*/

var privateKey  = fs.readFileSync('./certificate/private.pem', 'utf8');
var certificate = fs.readFileSync( './certificate/ca.cer', 'utf8');
var credentials = {key: privateKey, cert: certificate};

//创建https服务器

var httpsServer = https.createServer(credentials, app);

var SSLport = 3001;

httpsServer.listen(SSLport, function() {
    console.log('https Server is running on : xxx');
})
4. routes/index.js api设置
router.get('/index/card', function(req, res, next) {
  res.status(200).send(api.getCard('index'))
});
上一篇下一篇

猜你喜欢

热点阅读