代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/Easy-Mock 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
'use strict'
const Koa = require('koa')
const path = require('path')
const config = require('config')
const koaJwt = require('koa-jwt')
const cors = require('@koa/cors')
const koaBody = require('koa-body')
const onerror = require('koa-onerror')
const favicon = require('koa-favicon')
const validate = require('koa-validate')
const pathToRegexp = require('path-to-regexp')
const staticCache = require('koa-static-cache')
const util = require('./util')
const logger = require('./util/logger')
const middleware = require('./middlewares')
const routerConfig = require('./router-config')
const app = module.exports = new Koa()
const uploadConf = config.get('upload')
const jwtSecret = config.get('jwt.secret')
util.init()
onerror(app)
validate(app)
app
.use(middleware.ipFilter)
.use(favicon(path.join(__dirname, '/public/images/icon.png')))
.use(serve('/dist', './dist'))
.use(serve('/public', './public'))
.use(serve('/upload', path.resolve(__dirname, 'config', uploadConf.dir)))
.use(logger)
.use(middleware.util)
.use(cors({ credentials: true, maxAge: 2592000 }))
.use(koaJwt({ secret: jwtSecret }).unless((ctx) => {
if (/^\/api/.test(ctx.path)) {
return pathToRegexp([
'/api/u/login',
'/api/u/register',
'/api/mock/by_projects',
'/api/mock/export',
'/api/wallpaper'
]).test(ctx.path)
}
return true
}))
.use(koaBody({ multipart: true }))
.use(routerConfig.mock.routes())
.use(routerConfig.mock.allowedMethods())
.use(routerConfig.api.routes())
.use(routerConfig.api.allowedMethods())
app.proxy = config.get('proxy')
/* istanbul ignore if */
if (!module.parent) {
const port = config.get('port')
const host = config.get('host')
app.use(require('./middlewares/view').render(app))
app.listen(port, host)
console.log(`server started at http://${host}:${port}`)
}
function serve (prefix, filePath) {
return staticCache(path.resolve(__dirname, filePath), {
prefix: prefix,
gzip: true,
dynamic: true,
maxAge: 60 * 60 * 24 * 30
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。