const express = require(‘express‘)
const app = express()
const swig = require(‘swig‘)
const bodyParser = require(‘body-parser‘);
var mainRouter = require(‘./routers/main‘)
var apiRouter = require(‘./routers/api‘)
app.listen(3001,()=>{
console.log(‘http://localhost:3001‘);
})
/**
* 1,静态文件托管
*/
app.use(‘/public‘, express.static(__dirname + ‘/public‘)) // 【 设置 静态托管的目录 】
/**
* 2,设置解析
*/
app.use(bodyParser.urlencoded({ extended: true }))
/**
* 3,配置模板引擎
*/
app.engine(‘html‘, swig.renderFile)
app.set(‘views‘, ‘./views‘)
app.set(‘view engine‘, ‘html‘)
swig.setDefaults({ cache: false })
/**
* 4,配置路由
*/
app.use(‘/‘, mainRouter)
app.use(‘/api‘, apiRouter)