0x01 express 快速搭建
原文链接
1. 安装express-generator
$ npm install express-generator -g
2. 目录结构
image.png
- bin 文件
www入口文件
- public 静态资源
- routes 路由
- views 页面
app.js app主应用
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'))
});
网友评论