Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
app.js 970 Bytes
Copy Edit Raw Blame History
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const router = require('./router')
const logger = require('morgan')
const path = require('path')
const fs = require('fs')
// 创建 express 应用
const app = express()
require('./mongo')
const ENV = process.env.NODE_ENV
if (ENV !== 'production') {
// 开发环境 / 测试环境
app.use(logger('dev'))
} else {
// 线上环境
const logFileName = path.join(__dirname, 'logs', 'access.log')
const writeStream = fs.createWriteStream(logFileName, {
flags: 'a'
})
app.use(logger('combined', {
stream: writeStream
}))
}
//解决跨域问题
app.use(cors())
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(bodyParser.json())
app.use('/', router)
// 使 express 监听 5000 端口号发起的 http 请求
const server = app.listen(5000, function() {
// const { address, port } = server.address()
console.log('相关服务已经启动')
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化