mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-25 14:40:25 +08:00
feat: 因部署从git删除runtime,改为每次安装自动生成runtime/config.json配置
This commit is contained in:
parent
110548ba6b
commit
1fb2111c3c
3
.gitignore
vendored
3
.gitignore
vendored
@ -34,7 +34,6 @@ Thumbs.db
|
||||
# *.tar.gz
|
||||
|
||||
node_modules/
|
||||
runtime/init.lock
|
||||
runtime/log
|
||||
runtime/
|
||||
prd/
|
||||
dev/
|
||||
|
@ -5,8 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build-server": "babel server -d server_dist",
|
||||
"dev-server": "nodemon server_dist/app.js dev",
|
||||
"start": "webpack-dev-server"
|
||||
"dev-server": "nodemon server_dist/app.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"port": "3000",
|
||||
"webhost": "yapi.local.qunar.com",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "10.86.40.194",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017,
|
||||
"user": "test1",
|
||||
"pass": "test1"
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.163.com",
|
||||
"port": 465,
|
||||
"auth": {
|
||||
"user": "hellosean1025@163.com",
|
||||
"pass": "helloqunar123"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
{
|
||||
"port": "80",
|
||||
"webhost": "127.0.0.1",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "127.0.0.1",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.163.com",
|
||||
"port": 465,
|
||||
"auth": {
|
||||
"user": "***********@163.com",
|
||||
"pass": "*********"
|
||||
}
|
||||
}
|
||||
}
|
18
server/config.js
Normal file
18
server/config.js
Normal file
@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
"port": "3000",
|
||||
"webhost": "yapi.local.qunar.com",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "127.0.0.1",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.mail.com",
|
||||
"port": 4652,
|
||||
"auth": {
|
||||
"user": "****@mail.com",
|
||||
"pass": "**********"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
import initConfig from './utils/initConfig.js'
|
||||
import yapi from './yapi.js';
|
||||
import commons from './utils/commons';
|
||||
yapi.commons = commons;
|
||||
import dbModule from './utils/db.js';
|
||||
|
||||
import dbModule from './utils/db.js';
|
||||
import userModel from './models/user.js'
|
||||
|
||||
|
||||
yapi.commons = commons;
|
||||
yapi.connect = dbModule.connect()
|
||||
|
||||
|
||||
function install(){
|
||||
function install(){
|
||||
let exist = yapi.commons.fileExist(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock'))
|
||||
if(exist){
|
||||
return yapi.commons.log('runtime/init.lock文件已存在,请确认您是否已安装。如果需要重新安装,请删掉runtime/init.lock文件');
|
||||
@ -40,4 +42,4 @@ function setupSql(){
|
||||
})
|
||||
}
|
||||
|
||||
install();
|
||||
install()
|
@ -107,12 +107,16 @@ exports.sendMail = (options, cb) => {
|
||||
}
|
||||
|
||||
}
|
||||
yapi.mail.sendMail({
|
||||
try{
|
||||
yapi.mail.sendMail({
|
||||
from: yapi.WEBCONFIG.mail.auth.user,
|
||||
to: options.to,
|
||||
subject: 'yapi平台',
|
||||
html: options.contents
|
||||
}, cb)
|
||||
}, cb)
|
||||
}catch(e){
|
||||
console.error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
exports.validateSearchKeyword = keyword => {
|
||||
|
@ -6,8 +6,6 @@ function model(model, schema){
|
||||
if(schema instanceof mongoose.Schema === false){
|
||||
schema = new mongoose.Schema(schema);
|
||||
}
|
||||
|
||||
|
||||
schema.set('autoIndex', false);
|
||||
return yapi.connect.model(model, schema, model)
|
||||
}
|
||||
@ -15,11 +13,13 @@ function model(model, schema){
|
||||
function connect(){
|
||||
mongoose.Promise = global.Promise;
|
||||
let config = yapi.WEBCONFIG;
|
||||
let options = {};
|
||||
if(config.user){
|
||||
options.user = config.db.user,
|
||||
options.pass = config.db.pass
|
||||
}
|
||||
|
||||
let db = mongoose.connect(`mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`, {
|
||||
user: config.db.user,
|
||||
pass: config.db.pass
|
||||
});
|
||||
let db = mongoose.connect(`mongodb://${config.db.servername}:${config.db.port}/${config.db.DATABASE}`, options);
|
||||
|
||||
db.then(function (res) {
|
||||
yapi.commons.log('mongodb load success...')
|
||||
@ -28,7 +28,6 @@ function connect(){
|
||||
})
|
||||
|
||||
autoIncrement.initialize(db);
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
|
10
server/utils/initConfig.js
Normal file
10
server/utils/initConfig.js
Normal file
@ -0,0 +1,10 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs-extra'
|
||||
import config from '../config.js'
|
||||
|
||||
let configPath = path.join(path.resolve(__dirname, '../../'), 'runtime', 'config.json')
|
||||
|
||||
fs.writeFileSync(configPath,
|
||||
JSON.stringify(config, null, "\t"),
|
||||
{encoding: 'utf8'}
|
||||
)
|
@ -1,13 +1,10 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs-extra'
|
||||
import nodemailer from 'nodemailer';
|
||||
import prdConfig from '../runtime/config.json'
|
||||
import devConfig from '../runtime/config.dev.json'
|
||||
let args = process.argv.splice(2);
|
||||
let isDev = args[0] === 'dev' ? true : false;
|
||||
import config from '../runtime/config.json'
|
||||
|
||||
var insts = new Map();
|
||||
let mail;
|
||||
const config = isDev ? devConfig : prdConfig;
|
||||
|
||||
const WEBROOT = path.resolve(__dirname, '..'); //路径
|
||||
const WEBROOT_SERVER = __dirname;
|
||||
@ -15,6 +12,7 @@ const WEBROOT_RUNTIME = path.join(WEBROOT, 'runtime');
|
||||
const WEBROOT_LOG = path.join(WEBROOT_RUNTIME, 'log');
|
||||
const WEBCONFIG = config;
|
||||
|
||||
fs.ensureDirSync(WEBROOT_RUNTIME);
|
||||
fs.ensureDirSync(WEBROOT_LOG);
|
||||
|
||||
|
||||
@ -57,4 +55,4 @@ let r = {
|
||||
getInsts: insts
|
||||
}
|
||||
if(mail) r.mail = mail;
|
||||
module.exports = r;
|
||||
module.exports = r;
|
20
server_dist/config.js
Normal file
20
server_dist/config.js
Normal file
@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"port": "3000",
|
||||
"webhost": "yapi.local.qunar.com",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "127.0.0.1",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017
|
||||
},
|
||||
"mail": {
|
||||
"host": "smtp.mail.com",
|
||||
"port": 4652,
|
||||
"auth": {
|
||||
"user": "****@mail.com",
|
||||
"pass": "**********"
|
||||
}
|
||||
}
|
||||
};
|
@ -1,5 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var _fsExtra = require('fs-extra');
|
||||
|
||||
var _fsExtra2 = _interopRequireDefault(_fsExtra);
|
||||
|
||||
var _path = require('path');
|
||||
|
||||
var _path2 = _interopRequireDefault(_path);
|
||||
|
||||
var _initConfig = require('./utils/initConfig.js');
|
||||
|
||||
var _initConfig2 = _interopRequireDefault(_initConfig);
|
||||
|
||||
var _yapi = require('./yapi.js');
|
||||
|
||||
var _yapi2 = _interopRequireDefault(_yapi);
|
||||
@ -19,8 +31,6 @@ var _user2 = _interopRequireDefault(_user);
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
_yapi2.default.commons = _commons2.default;
|
||||
|
||||
|
||||
_yapi2.default.connect = _db2.default.connect();
|
||||
|
||||
function install() {
|
||||
|
@ -128,12 +128,16 @@ exports.sendMail = function (options, cb) {
|
||||
_yapi2.default.commons.log('send mail ' + options.to + ' success');
|
||||
}
|
||||
};
|
||||
_yapi2.default.mail.sendMail({
|
||||
from: _yapi2.default.WEBCONFIG.mail.auth.user,
|
||||
to: options.to,
|
||||
subject: 'yapi平台',
|
||||
html: options.contents
|
||||
}, cb);
|
||||
try {
|
||||
_yapi2.default.mail.sendMail({
|
||||
from: _yapi2.default.WEBCONFIG.mail.auth.user,
|
||||
to: options.to,
|
||||
subject: 'yapi平台',
|
||||
html: options.contents
|
||||
}, cb);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
exports.validateSearchKeyword = function (keyword) {
|
||||
|
@ -18,7 +18,6 @@ function model(model, schema) {
|
||||
if (schema instanceof _mongoose2.default.Schema === false) {
|
||||
schema = new _mongoose2.default.Schema(schema);
|
||||
}
|
||||
|
||||
schema.set('autoIndex', false);
|
||||
return _yapi2.default.connect.model(model, schema, model);
|
||||
}
|
||||
@ -26,11 +25,12 @@ function model(model, schema) {
|
||||
function connect() {
|
||||
_mongoose2.default.Promise = global.Promise;
|
||||
var config = _yapi2.default.WEBCONFIG;
|
||||
var options = {};
|
||||
if (config.user) {
|
||||
options.user = config.db.user, options.pass = config.db.pass;
|
||||
}
|
||||
|
||||
var db = _mongoose2.default.connect('mongodb://' + config.db.servername + ':' + config.db.port + '/' + config.db.DATABASE, {
|
||||
user: config.db.user,
|
||||
pass: config.db.pass
|
||||
});
|
||||
var db = _mongoose2.default.connect('mongodb://' + config.db.servername + ':' + config.db.port + '/' + config.db.DATABASE, options);
|
||||
|
||||
db.then(function (res) {
|
||||
_yapi2.default.commons.log('mongodb load success...');
|
||||
@ -39,7 +39,6 @@ function connect() {
|
||||
});
|
||||
|
||||
_mongooseAutoIncrement2.default.initialize(db);
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
|
23
server_dist/utils/initConfig.js
Normal file
23
server_dist/utils/initConfig.js
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
var _stringify = require('babel-runtime/core-js/json/stringify');
|
||||
|
||||
var _stringify2 = _interopRequireDefault(_stringify);
|
||||
|
||||
var _path = require('path');
|
||||
|
||||
var _path2 = _interopRequireDefault(_path);
|
||||
|
||||
var _fsExtra = require('fs-extra');
|
||||
|
||||
var _fsExtra2 = _interopRequireDefault(_fsExtra);
|
||||
|
||||
var _config = require('../config.js');
|
||||
|
||||
var _config2 = _interopRequireDefault(_config);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var configPath = _path2.default.join(_path2.default.resolve(__dirname, '../../'), 'runtime', 'config.json');
|
||||
|
||||
_fsExtra2.default.writeFileSync(configPath, (0, _stringify2.default)(_config2.default, null, "\t"), { encoding: 'utf8' });
|
@ -20,24 +20,18 @@ var _config = require('../runtime/config.json');
|
||||
|
||||
var _config2 = _interopRequireDefault(_config);
|
||||
|
||||
var _configDev = require('../runtime/config.dev.json');
|
||||
|
||||
var _configDev2 = _interopRequireDefault(_configDev);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var args = process.argv.splice(2);
|
||||
var isDev = args[0] === 'dev' ? true : false;
|
||||
var insts = new _map2.default();
|
||||
var mail = void 0;
|
||||
var config = isDev ? _configDev2.default : _config2.default;
|
||||
|
||||
var WEBROOT = _path2.default.resolve(__dirname, '..'); //路径
|
||||
var WEBROOT_SERVER = __dirname;
|
||||
var WEBROOT_RUNTIME = _path2.default.join(WEBROOT, 'runtime');
|
||||
var WEBROOT_LOG = _path2.default.join(WEBROOT_RUNTIME, 'log');
|
||||
var WEBCONFIG = config;
|
||||
var WEBCONFIG = _config2.default;
|
||||
|
||||
_fsExtra2.default.ensureDirSync(WEBROOT_RUNTIME);
|
||||
_fsExtra2.default.ensureDirSync(WEBROOT_LOG);
|
||||
|
||||
if (WEBCONFIG.mail) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user