美文网首页
express 后台搭建

express 后台搭建

作者: 2359634711 | 来源:发表于2019-03-19 22:39 被阅读0次

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')));
  • package.json 配置文件
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'))
});

相关文章

网友评论

      本文标题:express 后台搭建

      本文链接:https://www.haomeiwen.com/subject/qusomqtx.html