mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-12-09 14:40:27 +08:00
修改后台配置
This commit is contained in:
62
backend/src/config/index.ts
Normal file
62
backend/src/config/index.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
const envFound = dotenv.config();
|
||||
if (envFound.error) {
|
||||
|
||||
throw new Error("⚠️ Couldn't find .env file ⚠️");
|
||||
}
|
||||
|
||||
export default {
|
||||
port: parseInt(process.env.PORT, 10),
|
||||
databaseURL: process.env.MONGODB_URI,
|
||||
jwtSecret: process.env.JWT_SECRET,
|
||||
jwtAlgorithm: process.env.JWT_ALGO,
|
||||
options: {
|
||||
swaggerDefinition: {
|
||||
info: {
|
||||
description: 'This is a server',
|
||||
title: 'Swagger',
|
||||
version: '1.0.0'
|
||||
},
|
||||
host: `localhost:${parseInt(process.env.PORT, 10)}`,
|
||||
basePath: '/',
|
||||
produces: ['application/json', 'application/xml'],
|
||||
schemes: ['http', 'https'],
|
||||
securityDefinitions: {
|
||||
JWT: {
|
||||
type: 'apiKey',
|
||||
in: 'header',
|
||||
name: 'Authorization',
|
||||
description: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
route: {
|
||||
url: './swagger-ui.html',
|
||||
docs: '/swagger.json' //swagger文件 api
|
||||
},
|
||||
basedir: __dirname, //app absolute path
|
||||
files: ['../router/api/*.ts'] //Path to the API handle folder
|
||||
},
|
||||
logs: {
|
||||
level: process.env.LOG_LEVEL || 'silly',
|
||||
},
|
||||
agenda: {
|
||||
dbCollection: process.env.AGENDA_DB_COLLECTION,
|
||||
pooltime: process.env.AGENDA_POOL_TIME,
|
||||
concurrency: parseInt(process.env.AGENDA_CONCURRENCY, 10),
|
||||
},
|
||||
mysql: {
|
||||
user: 'admin',
|
||||
password: '123456'
|
||||
},
|
||||
api: {
|
||||
prefix: '/api',
|
||||
},
|
||||
emails: {
|
||||
apiKey: process.env.MAILGUN_API_KEY,
|
||||
domain: process.env.MAILGUN_DOMAIN
|
||||
}
|
||||
};
|
||||
35
backend/src/loaders/logger.ts
Normal file
35
backend/src/loaders/logger.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
import config from '../config';
|
||||
import * as winston from 'winston';
|
||||
|
||||
const transports = [];
|
||||
if(process.env.NODE_ENV !== 'development') {
|
||||
transports.push(
|
||||
new winston.transports.Console()
|
||||
)
|
||||
} else {
|
||||
transports.push(
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.cli(),
|
||||
winston.format.splat(),
|
||||
)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const LoggerInstance = winston.createLogger({
|
||||
level: config.logs.level,
|
||||
levels: winston.config.npm.levels,
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp({
|
||||
format: 'YYYY-MM-DD HH:mm:ss'
|
||||
}),
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.splat(),
|
||||
winston.format.json()
|
||||
),
|
||||
transports
|
||||
});
|
||||
|
||||
export default LoggerInstance;
|
||||
@@ -1,43 +1,26 @@
|
||||
import app from "./app";
|
||||
const PORT = 3000;
|
||||
import * as open from "open";
|
||||
import config from './config';
|
||||
import Logger from './loaders/logger';
|
||||
const expressSwagger = require('express-swagger-generator')(app)
|
||||
expressSwagger(config.options)
|
||||
|
||||
// 引入测试数据
|
||||
const test = require("./router/api/test")
|
||||
|
||||
let options = {
|
||||
swaggerDefinition: {
|
||||
info: {
|
||||
description: 'This is a sample server',
|
||||
title: 'Swagger',
|
||||
version: '1.0.0'
|
||||
},
|
||||
host: 'localhost:3000',
|
||||
basePath: '/',
|
||||
produces: ['application/json', 'application/xml'],
|
||||
schemes: ['http', 'https'],
|
||||
securityDefinitions: {
|
||||
JWT: {
|
||||
type: 'apiKey',
|
||||
in: 'header',
|
||||
name: 'Authorization',
|
||||
description: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
route: {
|
||||
url: '/swagger-ui.html',
|
||||
docs: '/swagger.json' //swagger文件 api
|
||||
},
|
||||
basedir: __dirname, //app absolute path
|
||||
files: ['./router/api/*.ts'] //Path to the API handle folder
|
||||
}
|
||||
expressSwagger(options)
|
||||
|
||||
app.get('/getApi', (req, res) => {
|
||||
test.testGetApi(req, res)
|
||||
})
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log('Swagger文档地址:', `http://localhost:${PORT}`);
|
||||
})
|
||||
app.listen(config.port, () => {
|
||||
Logger.info(`
|
||||
################################################
|
||||
🛡️ Swagger文档地址: http://localhost:${config.port} 🛡️
|
||||
################################################
|
||||
`);
|
||||
}).on('error', err => {
|
||||
Logger.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
open(`http://localhost:${config.port}`); // 自动打开默认浏览器
|
||||
Reference in New Issue
Block a user