mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
'use strict';
|
||
|
||
var _yapi = require('./yapi.js');
|
||
|
||
var _yapi2 = _interopRequireDefault(_yapi);
|
||
|
||
var _commons = require('./utils/commons');
|
||
|
||
var _commons2 = _interopRequireDefault(_commons);
|
||
|
||
var _db = require('./utils/db.js');
|
||
|
||
var _db2 = _interopRequireDefault(_db);
|
||
|
||
var _mockServer = require('./middleware/mockServer.js');
|
||
|
||
var _mockServer2 = _interopRequireDefault(_mockServer);
|
||
|
||
var _checkToken = require('./middleware/checkToken.js');
|
||
|
||
var _checkToken2 = _interopRequireDefault(_checkToken);
|
||
|
||
var _koa = require('koa');
|
||
|
||
var _koa2 = _interopRequireDefault(_koa);
|
||
|
||
var _koaConvert = require('koa-convert');
|
||
|
||
var _koaConvert2 = _interopRequireDefault(_koaConvert);
|
||
|
||
var _koaStatic = require('koa-static');
|
||
|
||
var _koaStatic2 = _interopRequireDefault(_koaStatic);
|
||
|
||
var _koaBodyparser = require('koa-bodyparser');
|
||
|
||
var _koaBodyparser2 = _interopRequireDefault(_koaBodyparser);
|
||
|
||
var _router = require('./router.js');
|
||
|
||
var _router2 = _interopRequireDefault(_router);
|
||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
||
_yapi2.default.commons = _commons2.default;
|
||
//checkToken作为中间件存在
|
||
|
||
|
||
_yapi2.default.connect = _db2.default.connect();
|
||
|
||
var app = new _koa2.default();
|
||
app.use(_mockServer2.default);
|
||
app.use((0, _koaBodyparser2.default)());
|
||
app.use(_router2.default.routes());
|
||
app.use(_router2.default.allowedMethods());
|
||
app.use((0, _koaStatic2.default)(_yapi2.default.path.join(_yapi2.default.WEBROOT, 'static')));
|
||
app.use(_checkToken2.default); //不是注册和登录,才需要检查token
|
||
app.listen(_yapi2.default.WEBCONFIG.port);
|
||
_commons2.default.log('the server is start at port ' + _yapi2.default.WEBCONFIG.port);
|
||
|
||
_yapi2.default.fs.ensureDirSync(_yapi2.default.WEBROOT_RUNTIME);
|
||
_yapi2.default.fs.ensureDirSync(_yapi2.default.WEBROOT_LOG); |