up
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": [
|
||||
[
|
||||
"babel-plugin-webpack-alias",
|
||||
{
|
||||
"config": "./webpack.config.js"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/logs/*
|
||||
/run/
|
||||
/typings/
|
||||
/node_modules/
|
||||
.github
|
||||
.idea
|
||||
@@ -0,0 +1,66 @@
|
||||
# bamboo 竹子
|
||||
|
||||
可视化开发小程序/H5/APP/API
|
||||
|
||||
## 一、目录结构
|
||||
|
||||
```sh
|
||||
manage
|
||||
|—— bin
|
||||
│ ├── main.js 服务入口文件
|
||||
│ ├── router.js koa路由
|
||||
│ ├── server.js pm2入口文件
|
||||
|—— app 应用
|
||||
|—— config 配置
|
||||
|—— logs 日志
|
||||
|—— public 静态资源目录
|
||||
|—— plugin 插件
|
||||
|—— pluginTemplate 插件模板
|
||||
client 客户端
|
||||
admin 管理端
|
||||
server 服务端
|
||||
```
|
||||
|
||||
> 文档树
|
||||
> 在写文档的时候,想把项目输出成文档树的形式,可以使用以下命令
|
||||
> tree >> D:/tree.txt 只有文件夹
|
||||
> tree /f >> D:/tree.txt 包括文件夹和文件
|
||||
|
||||
|
||||
**使用说明**
|
||||
|
||||
```sh
|
||||
npm run start #启动manage服务
|
||||
```
|
||||
|
||||
## 二、路由的定义
|
||||
|
||||
目录:manage>app>controller>home.js
|
||||
|
||||
```
|
||||
import router from 'bin/router';
|
||||
router.get('/home', async (ctx) => {
|
||||
ctx.body = 'ok'
|
||||
})
|
||||
export default router;
|
||||
```
|
||||
|
||||
## 三、中间件的定义与使用
|
||||
|
||||
目录:manage>app>middleware>load.js
|
||||
|
||||
```
|
||||
export default function load() {
|
||||
return async (ctx, next) => {
|
||||
const start = Date.now()
|
||||
await next()
|
||||
const responseTime = (Date.now() - start)
|
||||
console.log(`${ctx.host + ctx.url}响应时间为: ${responseTime / 1000}s`)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
http://static.kancloud.cn/manual/thinkphp6_0/1037483
|
||||
@@ -0,0 +1,7 @@
|
||||
//bamboo入口
|
||||
import Koa from 'koa';
|
||||
const app = new Koa();
|
||||
app.listen(3000);
|
||||
// module.exports = class bamboo {
|
||||
//
|
||||
// }
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//入口文件
|
||||
require('@babel/register')({
|
||||
presets: ['@babel/env'],
|
||||
plugins: [
|
||||
'@babel/plugin-transform-runtime',
|
||||
[
|
||||
'babel-plugin-webpack-alias',
|
||||
{
|
||||
"config": "./webpack.config.js"
|
||||
}
|
||||
]
|
||||
|
||||
]
|
||||
})
|
||||
require('@babel/polyfill')
|
||||
require('./bamboo/index')
|
||||
@@ -0,0 +1 @@
|
||||
/*应用配置*/
|
||||
@@ -0,0 +1 @@
|
||||
/*缓存配置*/
|
||||
@@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
keys: '',
|
||||
listen: {
|
||||
port: 32006,
|
||||
host: '0.0.0.0',
|
||||
},
|
||||
// 配置需要的中间件,数组顺序即为中间件的加载顺序
|
||||
middleware: ['jiujianJwt'],
|
||||
mysql: {
|
||||
host: '192.168.1.25',
|
||||
port: 3306,
|
||||
username: 'shichu',
|
||||
password: 'zXbAhBA26anGGEhY',
|
||||
},
|
||||
mongo: {},
|
||||
redis: {
|
||||
path: '',
|
||||
port: 32005,
|
||||
hostname: '0.0.0.0',
|
||||
},
|
||||
sequelize: {},
|
||||
/** 关闭csrf,否则api post将无法访问 */
|
||||
csrf: false,
|
||||
jwt: {
|
||||
secret: "_shichu",//自定义 token 的加密条件字符串
|
||||
expiresIn: "30d",//表示有效期 不带单位默认为秒 如带单位如: "2 days", "10h", "7d"
|
||||
},
|
||||
/** cors 允许跨域 */
|
||||
cors: {
|
||||
origin: '*',
|
||||
credentials: true,
|
||||
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
|
||||
},
|
||||
/** multipart 文件上传 */
|
||||
multipart: {
|
||||
whitelist: [// 文件白名单
|
||||
// images
|
||||
'.jpg', '.jpeg', // image/jpeg
|
||||
'.png', // image/png, image/x-png
|
||||
// '.gif', // image/gif
|
||||
// '.bmp', // image/bmp
|
||||
// '.wbmp', // image/vnd.wap.wbmp
|
||||
// '.webp',
|
||||
// '.tif',
|
||||
// '.psd',
|
||||
// // text
|
||||
// '.svg',
|
||||
// '.js', '.jsx',
|
||||
// '.json',
|
||||
// '.css', '.less',
|
||||
// '.html', '.htm',
|
||||
// '.xml',
|
||||
// // tar
|
||||
// '.zip',
|
||||
// '.gz', '.tgz', '.gzip',
|
||||
// // video
|
||||
// '.mp3',
|
||||
// '.mp4',
|
||||
// '.avi',
|
||||
'.p12',
|
||||
],
|
||||
},
|
||||
axios: {
|
||||
// can set more config in headers,like token,references and so on
|
||||
headers: {
|
||||
common: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
// 添加认证【例如】,也可以在请求拦截器中修改具体的request config
|
||||
// 'Authorization':'19980115_520' // 不要问我19980115是什么,当然是女朋友生日呀!!!
|
||||
},
|
||||
// 可以设置请求头等属性
|
||||
},
|
||||
// 定义请求拦截器处理方法【可选】
|
||||
// requestInterceptorsHandler: config => {
|
||||
// console.log('定义请求拦截器处理方法',config);
|
||||
// 请求之前的配置信息
|
||||
// 当该字段【函数】不存在是,默认如下:
|
||||
// app.coreLogger.debug(`[egg-axios-plus] send request, baseURL: ${JSON.stringify(baseURL)}, url: ${url}, method: ${method}, data: ${JSON.stringify(data)}, headers: ${JSON.stringify(headers)}`);
|
||||
// return config;
|
||||
// },
|
||||
// requestInterceptorsErrorHandler: error => {
|
||||
// // 请求之后发生的错误信息
|
||||
// // 当该字段【函数】不存在是,默认如下:
|
||||
// app.coreLogger.error(`[egg-axios-plus] send request error, ${error.message}`);
|
||||
// return Promise.reject(error);
|
||||
// },
|
||||
// // 定义axios响应拦截器处理方法【可选】
|
||||
// responseInterceptorsHandler: response => {
|
||||
// // response 响应结果
|
||||
// // 当该字段【函数】不存在是,默认如下:
|
||||
// app.coreLogger.debug(`[egg-axios-plus] receive response, data: ${JSON.stringify(response.data)}, status: ${response.status}, headers: ${JSON.stringify(response.headers)}`);
|
||||
// if (response.config && (response.method.toUpperCase() === 'HEAD' || response.method.toUpperCase() === 'options')) {
|
||||
// return response;
|
||||
// }
|
||||
// return response.data;
|
||||
// },
|
||||
responseInterceptorsErrorHandler: error => {
|
||||
// 接口响应失败的错误结果
|
||||
// 当该字段【函数】不存在是,默认如下:
|
||||
// app.coreLogger.error(`[egg-axios-plus] receive response error, ${error.message}`);
|
||||
console.log(`[egg-axios-plus] receive response error, ${error.message}`);
|
||||
return Promise.reject(error);
|
||||
},
|
||||
timeout: 12000, // 默认请求超时
|
||||
app: true, // 在app.js上启动加载
|
||||
agent: false, // 在agent.js上启动加载
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
/*控制台配置*/
|
||||
@@ -0,0 +1 @@
|
||||
/*数据库配置*/
|
||||
@@ -0,0 +1 @@
|
||||
/*文件磁盘配置*/
|
||||
@@ -0,0 +1 @@
|
||||
/*日志配置*/
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
import path from 'path';
|
||||
import bodyParser from 'koa-bodyparser';
|
||||
import staticFile from 'koa-static';
|
||||
export default {
|
||||
bodyParser: bodyParser(),
|
||||
staticFile: staticFile(path.resolve('pbulic')),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
export default {
|
||||
routerPlus: {
|
||||
enable: true,
|
||||
package: 'egg-router-plus',
|
||||
},
|
||||
jwt: {
|
||||
enable: true,
|
||||
package: "egg-jwt"
|
||||
},
|
||||
cors: {
|
||||
enable: true,
|
||||
package: 'egg-cors',
|
||||
},
|
||||
validate: {
|
||||
enable: true,
|
||||
package: 'egg-validate',
|
||||
},
|
||||
sequelize:{
|
||||
enable: true,
|
||||
package: 'egg-sequelize',
|
||||
},
|
||||
axiosPlus: {
|
||||
enable: true,
|
||||
package: 'egg-axios-plus',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/*URL和路由配置*/
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ignore": [
|
||||
".git",
|
||||
".svn",
|
||||
".idea",
|
||||
"node_modules/**/node_modules"
|
||||
],
|
||||
"exec": "node bin/main.js"
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "Koa-learn",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon",
|
||||
"start": "node bin/main.js",
|
||||
"server": "cross-env NODE_ENV=development nodemon bin/main.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
"@babel/plugin-transform-runtime": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"@babel/register": "^7.5.5",
|
||||
"art-template": "^4.13.2",
|
||||
"babel-plugin-webpack-alias": "^2.1.2",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-register": "^6.26.0",
|
||||
"cross-env": "^5.2.0",
|
||||
"ejs": "^2.6.2",
|
||||
"koa": "^2.7.0",
|
||||
"koa-art-template": "^1.1.1",
|
||||
"koa-bodyparser": "^4.2.1",
|
||||
"koa-router": "^7.4.0",
|
||||
"koa-session": "^5.12.2",
|
||||
"koa-static": "^5.0.0",
|
||||
"koa-views": "^6.2.0",
|
||||
"koa-webpack": "^6.0.0",
|
||||
"koa-webpack-middleware": "^1.0.7",
|
||||
"nodeenv": "^1.0.0",
|
||||
"nodemon": "^1.19.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.16.7",
|
||||
"@babel/node": "^7.16.8",
|
||||
"@babel/polyfill": "^7.4.4",
|
||||
"@babel/preset-env": "^7.16.8",
|
||||
"@babel/runtime": "^7.5.5",
|
||||
"babel-loader": "^8.2.3",
|
||||
"clean-webpack-plugin": "^4.0.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"koa-bodyparser": "^4.3.0",
|
||||
"pm2": "^5.1.2",
|
||||
"require-all": "^3.0.0",
|
||||
"require-directory": "^2.1.1",
|
||||
"shelljs": "^0.8.5",
|
||||
"webpack": "^4.41.5",
|
||||
"webpack-cli": "3.3.10",
|
||||
"webpack-node-externals": "^3.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/* pm2命令
|
||||
$ npm install pm2 -g # 命令行安装 pm2
|
||||
$ pm2 start app.js -i 4 # 后台运行pm2,启动4个app.js
|
||||
# 也可以把'max' 参数传递给 start
|
||||
# 正确的进程数目依赖于Cpu的核心数目
|
||||
$ pm2 start app.js --name my-api # 命名进程
|
||||
$ pm2 list # 显示所有进程状态
|
||||
$ pm2 monit # 监视所有进程
|
||||
$ pm2 logs # 显示所有进程日志
|
||||
$ pm2 stop all # 停止所有进程
|
||||
$ pm2 restart all # 重启所有进程
|
||||
$ pm2 reload all # 0 秒停机重载进程 (用于 NETWORKED 进程)
|
||||
$ pm2 stop 0 # 停止指定的进程
|
||||
$ pm2 restart 0 # 重启指定的进程
|
||||
$ pm2 startup # 产生 init 脚本 保持进程活着
|
||||
$ pm2 web # 运行健壮的 computer API endpoint (http://localhost:9615)
|
||||
$ pm2 delete 0 # 杀死指定的进程
|
||||
$ pm2 delete all # 杀死全部进程
|
||||
*/
|
||||
|
||||
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'bamboo_manage', // 项目名
|
||||
script: './bin/main.js', // 执行文件
|
||||
cwd: './', // 根目录
|
||||
args: '', // 传递给脚本的参数
|
||||
interpreter: '', // 指定的脚本解释器
|
||||
interpreter_args: '', // 传递给解释器的参数
|
||||
exec_mode: 'fork', // 应用启动模式,支持fork和cluster模式
|
||||
instances: 1, // 应用启动实例个数,仅在cluster模式有效 默认为fork;或者 max
|
||||
max_memory_restart: '1G', // 最大内存限制数,超出自动重启
|
||||
error_file: './logs/pm2/error.log', //错误输出日志
|
||||
out_file: './logs/pm2/out.log', //日志
|
||||
merge_logs: true, // 设置追加日志而不是新建日志
|
||||
log_date_format: 'YYYY-MM-DD HH:mm:ss', // 指定日志文件的时间格式
|
||||
min_uptime: 1000, // 应用运行少于时间被认为是异常启动
|
||||
max_restarts: 30, // 最大异常重启次数,即小于min_uptime运行时间重启次数;
|
||||
autorestart: true, // 默认为true, 发生异常的情况下自动重启
|
||||
cron_restart: '', // crontab时间格式重启应用,目前只支持cluster模式;
|
||||
restart_delay: 60, // 异常重启情况下,延时重启时间
|
||||
watch: true, // 是否监听文件变动然后重启
|
||||
// exec_interpreter: "babel-node", //此配置就是使用babel-node去执行nodejs文件
|
||||
ignore_watch: [
|
||||
// 不用监听的文件
|
||||
'node_modules',
|
||||
'logs',
|
||||
'news',
|
||||
'run',
|
||||
'test',
|
||||
'typings',
|
||||
'public',
|
||||
'pm2.config'
|
||||
],
|
||||
// 使用 process.env.NODE_ENV
|
||||
env: {
|
||||
NODE_ENV: 'development'
|
||||
},
|
||||
env_production: {
|
||||
NODE_ENV: 'production'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
const path = require('path');
|
||||
const nodeExternals = require('webpack-node-externals');
|
||||
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
|
||||
const webpackconfig = {
|
||||
target: 'node',
|
||||
mode: 'development',
|
||||
entry: {
|
||||
server: path.resolve('bin/main.js')
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
alias: {
|
||||
'app': path.resolve('app'),
|
||||
'bin': path.resolve('bin'),
|
||||
'config': path.resolve('config'),
|
||||
'middleware': path.resolve('middleware'),
|
||||
'public': path.resolve('public'),
|
||||
},
|
||||
},
|
||||
devtool: 'eval-source-map',
|
||||
output: {
|
||||
filename: '[name].bundle.js',
|
||||
path: path.resolve('./dist')
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\/(js|jsx)$/,
|
||||
use: {
|
||||
loader: 'babel-loader'
|
||||
},
|
||||
exclude: [path.resolve('/node_modules')]
|
||||
}
|
||||
],
|
||||
},
|
||||
externals: [nodeExternals()],
|
||||
plugins: [
|
||||
new CleanWebpackPlugin()
|
||||
],
|
||||
node: {
|
||||
console: true,
|
||||
global: true,
|
||||
process: true,
|
||||
Buffer: true,
|
||||
__filename: true,
|
||||
__dirname: true,
|
||||
setImmediate: true,
|
||||
path: true
|
||||
}
|
||||
}
|
||||
module.exports = webpackconfig
|
||||
Reference in New Issue
Block a user