🎨 update readme
This commit is contained in:
parent
e354812501
commit
2047777abe
207
.eslintrc.js
207
.eslintrc.js
@ -1,207 +0,0 @@
|
|||||||
// module.exports = {
|
|
||||||
// root: true,
|
|
||||||
// parserOptions: {
|
|
||||||
// parser: 'babel-eslint',
|
|
||||||
// sourceType: 'module'
|
|
||||||
// },
|
|
||||||
// env: {
|
|
||||||
// browser: true,
|
|
||||||
// node: true,
|
|
||||||
// es6: true,
|
|
||||||
// },
|
|
||||||
// extends: ['plugin:vue/recommended', 'eslint:recommended'],
|
|
||||||
//
|
|
||||||
// // add your custom rules here
|
|
||||||
// //it is base on https://github.com/vuejs/eslint-config-vue
|
|
||||||
// rules: {
|
|
||||||
// "vue/html-self-closing": ["error",{
|
|
||||||
// "html": {
|
|
||||||
// "void": "never",
|
|
||||||
// "normal": "any",
|
|
||||||
// "component": "any"
|
|
||||||
// },
|
|
||||||
// "svg": "always",
|
|
||||||
// "math": "always"
|
|
||||||
// }],
|
|
||||||
// "vue/max-attributes-per-line": [2, {
|
|
||||||
// "singleline": 10,
|
|
||||||
// "multiline": {
|
|
||||||
// "max": 1,
|
|
||||||
// "allowFirstLine": false
|
|
||||||
// }
|
|
||||||
// }],
|
|
||||||
// "vue/singleline-html-element-content-newline": "off",
|
|
||||||
// "vue/multiline-html-element-content-newline":"off",
|
|
||||||
// "vue/name-property-casing": ["error", "PascalCase"],
|
|
||||||
// "vue/no-v-html": "off",
|
|
||||||
// 'accessor-pairs': 2,
|
|
||||||
// 'arrow-spacing': [2, {
|
|
||||||
// 'before': true,
|
|
||||||
// 'after': true
|
|
||||||
// }],
|
|
||||||
// 'block-spacing': [2, 'always'],
|
|
||||||
// 'brace-style': [2, '1tbs', {
|
|
||||||
// 'allowSingleLine': true
|
|
||||||
// }],
|
|
||||||
// 'camelcase': [0, {
|
|
||||||
// 'properties': 'always'
|
|
||||||
// }],
|
|
||||||
// 'comma-dangle': [2, 'never'],
|
|
||||||
// 'comma-spacing': [2, {
|
|
||||||
// 'before': false,
|
|
||||||
// 'after': true
|
|
||||||
// }],
|
|
||||||
// 'comma-style': [2, 'last'],
|
|
||||||
// 'constructor-super': 2,
|
|
||||||
// 'curly': [2, 'multi-line'],
|
|
||||||
// 'dot-location': [2, 'property'],
|
|
||||||
// 'eol-last': 2,
|
|
||||||
// 'eqeqeq': ["error", "always", {"null": "ignore"}],
|
|
||||||
// 'generator-star-spacing': [2, {
|
|
||||||
// 'before': true,
|
|
||||||
// 'after': true
|
|
||||||
// }],
|
|
||||||
// 'handle-callback-err': [2, '^(err|error)$'],
|
|
||||||
// 'indent': [2, 2, {
|
|
||||||
// 'SwitchCase': 1
|
|
||||||
// }],
|
|
||||||
// 'jsx-quotes': [2, 'prefer-single'],
|
|
||||||
// 'key-spacing': [2, {
|
|
||||||
// 'beforeColon': false,
|
|
||||||
// 'afterColon': true
|
|
||||||
// }],
|
|
||||||
// 'keyword-spacing': [2, {
|
|
||||||
// 'before': true,
|
|
||||||
// 'after': true
|
|
||||||
// }],
|
|
||||||
// 'new-cap': [2, {
|
|
||||||
// 'newIsCap': true,
|
|
||||||
// 'capIsNew': false
|
|
||||||
// }],
|
|
||||||
// 'new-parens': 2,
|
|
||||||
// 'no-array-constructor': 2,
|
|
||||||
// 'no-caller': 2,
|
|
||||||
// 'no-console': 'off',
|
|
||||||
// 'no-class-assign': 2,
|
|
||||||
// 'no-cond-assign': 2,
|
|
||||||
// 'no-const-assign': 2,
|
|
||||||
// 'no-control-regex': 0,
|
|
||||||
// 'no-delete-var': 2,
|
|
||||||
// 'no-dupe-args': 2,
|
|
||||||
// 'no-dupe-class-members': 2,
|
|
||||||
// 'no-dupe-keys': 2,
|
|
||||||
// 'no-duplicate-case': 2,
|
|
||||||
// 'no-empty-character-class': 2,
|
|
||||||
// 'no-empty-pattern': 2,
|
|
||||||
// 'no-eval': 2,
|
|
||||||
// 'no-ex-assign': 2,
|
|
||||||
// 'no-extend-native': 2,
|
|
||||||
// 'no-extra-bind': 2,
|
|
||||||
// 'no-extra-boolean-cast': 2,
|
|
||||||
// 'no-extra-parens': [2, 'functions'],
|
|
||||||
// 'no-fallthrough': 2,
|
|
||||||
// 'no-floating-decimal': 2,
|
|
||||||
// 'no-func-assign': 2,
|
|
||||||
// 'no-implied-eval': 2,
|
|
||||||
// 'no-inner-declarations': [2, 'functions'],
|
|
||||||
// 'no-invalid-regexp': 2,
|
|
||||||
// 'no-irregular-whitespace': 2,
|
|
||||||
// 'no-iterator': 2,
|
|
||||||
// 'no-label-var': 2,
|
|
||||||
// 'no-labels': [2, {
|
|
||||||
// 'allowLoop': false,
|
|
||||||
// 'allowSwitch': false
|
|
||||||
// }],
|
|
||||||
// 'no-lone-blocks': 2,
|
|
||||||
// 'no-mixed-spaces-and-tabs': 2,
|
|
||||||
// 'no-multi-spaces': 2,
|
|
||||||
// 'no-multi-str': 2,
|
|
||||||
// 'no-multiple-empty-lines': [2, {
|
|
||||||
// 'max': 1
|
|
||||||
// }],
|
|
||||||
// 'no-native-reassign': 2,
|
|
||||||
// 'no-negated-in-lhs': 2,
|
|
||||||
// 'no-new-object': 2,
|
|
||||||
// 'no-new-require': 2,
|
|
||||||
// 'no-new-symbol': 2,
|
|
||||||
// 'no-new-wrappers': 2,
|
|
||||||
// 'no-obj-calls': 2,
|
|
||||||
// 'no-octal': 2,
|
|
||||||
// 'no-octal-escape': 2,
|
|
||||||
// 'no-path-concat': 2,
|
|
||||||
// 'no-proto': 2,
|
|
||||||
// 'no-redeclare': 2,
|
|
||||||
// 'no-regex-spaces': 2,
|
|
||||||
// 'no-return-assign': [2, 'except-parens'],
|
|
||||||
// 'no-self-assign': 2,
|
|
||||||
// 'no-self-compare': 2,
|
|
||||||
// 'no-sequences': 2,
|
|
||||||
// 'no-shadow-restricted-names': 2,
|
|
||||||
// 'no-spaced-func': 2,
|
|
||||||
// 'no-sparse-arrays': 2,
|
|
||||||
// 'no-this-before-super': 2,
|
|
||||||
// 'no-throw-literal': 2,
|
|
||||||
// 'no-trailing-spaces': 2,
|
|
||||||
// 'no-undef': 2,
|
|
||||||
// 'no-undef-init': 2,
|
|
||||||
// 'no-unexpected-multiline': 2,
|
|
||||||
// 'no-unmodified-loop-condition': 2,
|
|
||||||
// 'no-unneeded-ternary': [2, {
|
|
||||||
// 'defaultAssignment': false
|
|
||||||
// }],
|
|
||||||
// 'no-unreachable': 2,
|
|
||||||
// 'no-unsafe-finally': 2,
|
|
||||||
// 'no-unused-vars': [2, {
|
|
||||||
// 'vars': 'all',
|
|
||||||
// 'args': 'none'
|
|
||||||
// }],
|
|
||||||
// 'no-useless-call': 2,
|
|
||||||
// 'no-useless-computed-key': 2,
|
|
||||||
// 'no-useless-constructor': 2,
|
|
||||||
// 'no-useless-escape': 0,
|
|
||||||
// 'no-whitespace-before-property': 2,
|
|
||||||
// 'no-with': 2,
|
|
||||||
// 'one-var': [2, {
|
|
||||||
// 'initialized': 'never'
|
|
||||||
// }],
|
|
||||||
// 'operator-linebreak': [2, 'after', {
|
|
||||||
// 'overrides': {
|
|
||||||
// '?': 'before',
|
|
||||||
// ':': 'before'
|
|
||||||
// }
|
|
||||||
// }],
|
|
||||||
// 'padded-blocks': [2, 'never'],
|
|
||||||
// 'quotes': [2, 'single', {
|
|
||||||
// 'avoidEscape': true,
|
|
||||||
// 'allowTemplateLiterals': true
|
|
||||||
// }],
|
|
||||||
// 'semi': [2, 'never'],
|
|
||||||
// 'semi-spacing': [2, {
|
|
||||||
// 'before': false,
|
|
||||||
// 'after': true
|
|
||||||
// }],
|
|
||||||
// 'space-before-blocks': [2, 'always'],
|
|
||||||
// 'space-before-function-paren': [2, 'never'],
|
|
||||||
// 'space-in-parens': [2, 'never'],
|
|
||||||
// 'space-infix-ops': 2,
|
|
||||||
// 'space-unary-ops': [2, {
|
|
||||||
// 'words': true,
|
|
||||||
// 'nonwords': false
|
|
||||||
// }],
|
|
||||||
// 'spaced-comment': [2, 'always', {
|
|
||||||
// 'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
|
|
||||||
// }],
|
|
||||||
// 'template-curly-spacing': [2, 'never'],
|
|
||||||
// 'use-isnan': 2,
|
|
||||||
// 'valid-typeof': 2,
|
|
||||||
// 'wrap-iife': [2, 'any'],
|
|
||||||
// 'yield-star-spacing': [2, 'both'],
|
|
||||||
// 'yoda': [2, 'never'],
|
|
||||||
// 'prefer-const': 2,
|
|
||||||
// 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
|
||||||
// 'object-curly-spacing': [2, 'always', {
|
|
||||||
// objectsInObjects: false
|
|
||||||
// }],
|
|
||||||
// 'array-bracket-spacing': [2, 'never']
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
132
README.md
132
README.md
@ -19,91 +19,65 @@ JmalCloud 是一款私有云存储网盘项目,能够简单安全管理您的
|
|||||||

|

|
||||||
|
|
||||||
### 部署
|
### 部署
|
||||||
下面两种方式二选一
|
**以下两种启动方式二选一, 推荐使用[docker-compose](https://docs.docker.com/compose//)**
|
||||||
### 部署方式一:[docker部署](https://blog.jmal.top/s/docker-jmalcloud) (推荐)
|
|
||||||
#### 1.拉取镜像
|
> docker run 方式启动
|
||||||
`docker pull registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest`
|
|
||||||
#### 2.运行
|
```shell
|
||||||
`docker run --restart=always --name jmalcloud -p 7070:80 -p 7071:8080 -p 7072:8088 -v /Users/jmal/temp/jmalcloud-docker/files/:/jmalcloud/files/ -v /Users/jmal/temp/jmalcloud-docker/db/:/data/db/ -d registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest`
|
docker run \
|
||||||
|
--restart=always \
|
||||||
|
--name jmalcloud \
|
||||||
|
-p 7070:80 \
|
||||||
|
-p 7071:8080 \
|
||||||
|
-p 7072:8088 \
|
||||||
|
-p 27018:27017 \
|
||||||
|
-v /Users/jmal/temp/jmalcloud-docker/files/:/jmalcloud/files/ \
|
||||||
|
-v /Users/jmal/temp/jmalcloud-docker/db/:/data/db/ \
|
||||||
|
-d registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest
|
||||||
```
|
```
|
||||||
启动参数说明 :
|
|
||||||
暴露端口 :
|
> docker-compose 方式启动
|
||||||
`80` : 网盘入口
|
|
||||||
`8080` : 博客入口
|
编辑docker-compose.yml文件
|
||||||
`8088` : 网盘服务入口
|
|
||||||
磁盘映射 :
|
```yaml
|
||||||
|
version: "3.5"
|
||||||
|
services:
|
||||||
|
jmalcloud:
|
||||||
|
image: registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest
|
||||||
|
container_name: jmalcloud
|
||||||
|
volumes:
|
||||||
|
- /Users/jmal/temp/jmalcloud-docker/files/:/jmalcloud/files/
|
||||||
|
- /Users/jmal/temp/jmalcloud-docker/db/:/data/db/
|
||||||
|
ports:
|
||||||
|
- "7070:80"
|
||||||
|
- "7071:8080"
|
||||||
|
- "7072:8088"
|
||||||
|
- "27018:27017"
|
||||||
|
```
|
||||||
|
|
||||||
|
启动:在docker-compose.yml文件目录下运行以下命令
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker-compse up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
> 启动参数
|
||||||
|
|
||||||
|
Port :
|
||||||
|
`7070` : 网盘入口
|
||||||
|
`7071` : 博客入口
|
||||||
|
`7072` : 网盘api入口, 例如:http://localhost:7072/public/doc.html
|
||||||
|
`27018` : MongoDB
|
||||||
|
Volume :
|
||||||
`/jmalcloud/files/` : 网盘文件存储目录
|
`/jmalcloud/files/` : 网盘文件存储目录
|
||||||
`/data/db/` : mongodb数据存储目录
|
`/data/db/` : mongodb数据存储目录
|
||||||
```
|
|
||||||
#### 3.访问 7070 端口试试看 出现创建管理员的界面说明部署成功
|
|
||||||
|
|
||||||
### 部署方式二
|
> 访问试试看
|
||||||
|
|
||||||
#### 1.环境准备
|
|
||||||
|
|
||||||
- nginx 1.18+
|
|
||||||
- mongodb 4.0+
|
|
||||||
- jdk 1.8+
|
|
||||||
|
|
||||||
#### 2.下载网盘界面程序,并配置nginx
|
|
||||||
|
|
||||||
去[这里](https://github.com/jamebal/jmal-cloud-view/releases)下载最新的版本,选择dist.tar下载
|
|
||||||
|
|
||||||
下载后解压到某个地方
|
|
||||||
|
|
||||||
nginx配置如下: (只需要修改两个地方)
|
|
||||||
|
|
||||||
```nginx
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
# 1.这里填写你的ip地址,或域名
|
|
||||||
server_name xxx;
|
|
||||||
# 2.这填写为dist.tar解压后的路径
|
|
||||||
root xxx;
|
|
||||||
client_max_body_size 50m;
|
|
||||||
client_body_buffer_size 512k;
|
|
||||||
|
|
||||||
location /api/ {
|
|
||||||
proxy_pass http://localhost:8088/;
|
|
||||||
proxy_set_header Host $proxy_host;
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
index index.html index.htm;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /mq/ {
|
|
||||||
proxy_pass http://localhost:8088/mq/;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
proxy_connect_timeout 60s;
|
|
||||||
proxy_read_timeout 500s;
|
|
||||||
proxy_send_timeout 500s;
|
|
||||||
}
|
|
||||||
|
|
||||||
location ~ \.(eot|otf|ttf|woff|woff2|svg)$ {
|
|
||||||
add_header Access-Control-Allow-Origin *;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3.下载网盘服务程序
|
|
||||||
|
|
||||||
去[这里](https://github.com/jamebal/jmal-cloud-server/releases)下载最新的jar包
|
|
||||||
|
|
||||||
启动(需要提前安装jdk,mongodb环境)
|
|
||||||
|
|
||||||
`java -jar clouddisk-2.0-exec.jar --spring.profiles.active=prod --file.rootDir=xxx`
|
|
||||||
|
|
||||||
其中`file.rootDir`为网盘文件真实的存储的位置
|
|
||||||
|
|
||||||
#### 4.访问
|
|
||||||
在浏览器里直接输入你的IP或域名即可
|
|
||||||
|
|
||||||
|
启动后等待40秒左右,访问7070端口看到如下界面,说明部署成功
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
### 浏览器支持
|
### 浏览器支持
|
||||||
|
|
||||||
|
|||||||
134
README_en_US.md
134
README_en_US.md
@ -19,92 +19,66 @@ Some screenshots:
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
### Deployment
|
### deploy
|
||||||
Choose one of the following two ways
|
**Either of the following two startup methods is recommended[docker-compose](https://docs.docker.com/compose//)**
|
||||||
### Deployment method one: [docker deployment](https://blog.jmal.top/s/docker-jmalcloud) (recommended)
|
|
||||||
#### 1. Pull image
|
> docker run
|
||||||
`docker pull registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest`
|
|
||||||
#### 2. Run
|
```shell
|
||||||
`docker run --restart=always --name jmalcloud -p 7070:80 -p 7071:8080 -p 7072:8088 -v /Users/jmal/temp/jmalcloud-docker/files/:/ jmalcloud/files/ -v /Users/jmal/temp/jmalcloud-docker/db/:/data/db/ -d registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud: latest`
|
docker run \
|
||||||
|
--restart=always \
|
||||||
|
--name jmalcloud \
|
||||||
|
-p 7070:80 \
|
||||||
|
-p 7071:8080 \
|
||||||
|
-p 7072:8088 \
|
||||||
|
-p 27018:27017 \
|
||||||
|
-v /Users/jmal/temp/jmalcloud-docker/files/:/jmalcloud/files/ \
|
||||||
|
-v /Users/jmal/temp/jmalcloud-docker/db/:/data/db/ \
|
||||||
|
-d registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest
|
||||||
```
|
```
|
||||||
Start parameters description :
|
|
||||||
Expose port :
|
> docker-compose
|
||||||
`80` : Web portal
|
|
||||||
`8080` : Blog entry
|
docker-compose.yml
|
||||||
`8088` : Netdisk service entry
|
|
||||||
Disk mapping :
|
```yaml
|
||||||
|
version: "3.5"
|
||||||
|
services:
|
||||||
|
jmalcloud:
|
||||||
|
image: registry.cn-guangzhou.aliyuncs.com/jmalcloud/jmalcloud:latest
|
||||||
|
container_name: jmalcloud
|
||||||
|
volumes:
|
||||||
|
- /Users/jmal/temp/jmalcloud-docker/files/:/jmalcloud/files/
|
||||||
|
- /Users/jmal/temp/jmalcloud-docker/db/:/data/db/
|
||||||
|
ports:
|
||||||
|
- "7070:80"
|
||||||
|
- "7071:8080"
|
||||||
|
- "7072:8088"
|
||||||
|
- "27018:27017"
|
||||||
|
```
|
||||||
|
|
||||||
|
Start: Run the following command in the docker-compose.yml file directory
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker-compse up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
> Start-up parameters
|
||||||
|
|
||||||
|
Port :
|
||||||
|
`7070` : Web portal
|
||||||
|
`7071` : Blog portal
|
||||||
|
`7072` : Web api portal, 例如:http://localhost:7072/public/doc.html
|
||||||
|
`27018` : MongoDB
|
||||||
|
Volume :
|
||||||
`/jmalcloud/files/` : Netdisk file storage directory
|
`/jmalcloud/files/` : Netdisk file storage directory
|
||||||
`/data/db/` : mongodb data storage directory
|
`/data/db/` : mongodb data storage directory
|
||||||
```
|
|
||||||
#### 3. Visit port 7070 and try it. The interface of creating administrator appears to indicate successful deployment
|
|
||||||
|
|
||||||
### Deployment method 2
|
> Try visiting
|
||||||
|
|
||||||
#### 1.Environmental Preparation
|
|
||||||
|
|
||||||
- nginx 1.18+
|
|
||||||
- mongodb 4.0+
|
|
||||||
- jdk 1.8+
|
|
||||||
|
|
||||||
#### 2.Download the web interface program and configure nginx
|
|
||||||
|
|
||||||
Go to[here](https://github.com/jamebal/jmal-cloud-view/releases)Download the latest version, select dist.tar to download
|
|
||||||
|
|
||||||
Download and unpack it somewhere
|
|
||||||
|
|
||||||
The nginx configuration is as follows: (only two places need to be modified)
|
|
||||||
|
|
||||||
```nginx
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
# 1.Here fill in your ip address, or domain name
|
|
||||||
server_name xxx;
|
|
||||||
# 2.This is the path to the extracted dist.tar
|
|
||||||
root xxx;
|
|
||||||
client_max_body_size 50m;
|
|
||||||
client_body_buffer_size 512k;
|
|
||||||
|
|
||||||
location /api/ {
|
|
||||||
proxy_pass http://localhost:8088/;
|
|
||||||
proxy_set_header Host $proxy_host;
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
index index.html index.htm;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /mq/ {
|
|
||||||
proxy_pass http://localhost:8088/mq/;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
proxy_connect_timeout 60s;
|
|
||||||
proxy_read_timeout 500s;
|
|
||||||
proxy_send_timeout 500s;
|
|
||||||
}
|
|
||||||
|
|
||||||
location ~ \.(eot|otf|ttf|woff|woff2|svg)$ {
|
|
||||||
add_header Access-Control-Allow-Origin *;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3.Download the netdisk service program
|
|
||||||
|
|
||||||
Go to[here](https://github.com/jamebal/jmal-cloud-server/releases)Download the latest jar packages
|
|
||||||
|
|
||||||
Start (need to install jdk, mongodb environment in advance)
|
|
||||||
|
|
||||||
`java -jar clouddisk-2.0-exec.jar --spring.profiles.active=prod --file.rootDir=xxx`
|
|
||||||
|
|
||||||
where `file.rootDir` is the real storage location of the netdisk file
|
|
||||||
|
|
||||||
#### 4.access
|
|
||||||
Just type your IP or domain name directly into your browser
|
|
||||||
|
|
||||||
|
Wait for about 40 seconds after startup, access port 7070 and see the following screen, indicating successful deployment
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
### Browser Support
|
### Browser Support
|
||||||
|
|
||||||
|
|||||||
@ -1,67 +0,0 @@
|
|||||||
import Mock from 'mockjs'
|
|
||||||
import { param2Obj } from '../src/utils'
|
|
||||||
|
|
||||||
import user from './user'
|
|
||||||
import table from './table'
|
|
||||||
|
|
||||||
const mocks = [
|
|
||||||
...user,
|
|
||||||
...table
|
|
||||||
]
|
|
||||||
|
|
||||||
// for front mock
|
|
||||||
// please use it cautiously, it will redefine XMLHttpRequest,
|
|
||||||
// which will cause many of your third-party libraries to be invalidated(like progress event).
|
|
||||||
export function mockXHR() {
|
|
||||||
// mock patch
|
|
||||||
// https://github.com/nuysoft/Mock/issues/300
|
|
||||||
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
|
|
||||||
Mock.XHR.prototype.send = function() {
|
|
||||||
if (this.custom.xhr) {
|
|
||||||
this.custom.xhr.withCredentials = this.withCredentials || false
|
|
||||||
|
|
||||||
if (this.responseType) {
|
|
||||||
this.custom.xhr.responseType = this.responseType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.proxy_send(...arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
function XHR2ExpressReqWrap(respond) {
|
|
||||||
return function(options) {
|
|
||||||
let result = null
|
|
||||||
if (respond instanceof Function) {
|
|
||||||
const { body, type, url } = options
|
|
||||||
// https://expressjs.com/en/4x/api.html#req
|
|
||||||
result = respond({
|
|
||||||
method: type,
|
|
||||||
body: JSON.parse(body),
|
|
||||||
query: param2Obj(url)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
result = respond
|
|
||||||
}
|
|
||||||
return Mock.mock(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const i of mocks) {
|
|
||||||
Mock.mock(new RegExp(i.url), i.type || 'get', XHR2ExpressReqWrap(i.response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for mock server
|
|
||||||
const responseFake = (url, type, respond) => {
|
|
||||||
return {
|
|
||||||
url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}`),
|
|
||||||
type: type || 'get',
|
|
||||||
response(req, res) {
|
|
||||||
console.log('request invoke:' + req.path)
|
|
||||||
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default mocks.map(route => {
|
|
||||||
return responseFake(route.url, route.type, route.response)
|
|
||||||
})
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
const chokidar = require('chokidar')
|
|
||||||
const bodyParser = require('body-parser')
|
|
||||||
const chalk = require('chalk')
|
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
const mockDir = path.join(process.cwd(), 'mock')
|
|
||||||
|
|
||||||
function registerRoutes(app) {
|
|
||||||
let mockLastIndex
|
|
||||||
const { default: mocks } = require('./index.js')
|
|
||||||
for (const mock of mocks) {
|
|
||||||
app[mock.type](mock.url, mock.response)
|
|
||||||
mockLastIndex = app._router.stack.length
|
|
||||||
}
|
|
||||||
const mockRoutesLength = Object.keys(mocks).length
|
|
||||||
return {
|
|
||||||
mockRoutesLength: mockRoutesLength,
|
|
||||||
mockStartIndex: mockLastIndex - mockRoutesLength
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function unregisterRoutes() {
|
|
||||||
Object.keys(require.cache).forEach(i => {
|
|
||||||
if (i.includes(mockDir)) {
|
|
||||||
delete require.cache[require.resolve(i)]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = app => {
|
|
||||||
// es6 polyfill
|
|
||||||
require('@babel/register')
|
|
||||||
|
|
||||||
// parse app.body
|
|
||||||
// https://expressjs.com/en/4x/api.html#req.body
|
|
||||||
app.use(bodyParser.json())
|
|
||||||
app.use(bodyParser.urlencoded({
|
|
||||||
extended: true
|
|
||||||
}))
|
|
||||||
|
|
||||||
const mockRoutes = registerRoutes(app)
|
|
||||||
var mockRoutesLength = mockRoutes.mockRoutesLength
|
|
||||||
var mockStartIndex = mockRoutes.mockStartIndex
|
|
||||||
|
|
||||||
// watch files, hot reload mock server
|
|
||||||
chokidar.watch(mockDir, {
|
|
||||||
ignored: /mock-server/,
|
|
||||||
ignoreInitial: true
|
|
||||||
}).on('all', (event, path) => {
|
|
||||||
if (event === 'change' || event === 'add') {
|
|
||||||
try {
|
|
||||||
// remove mock routes stack
|
|
||||||
app._router.stack.splice(mockStartIndex, mockRoutesLength)
|
|
||||||
|
|
||||||
// clear routes cache
|
|
||||||
unregisterRoutes()
|
|
||||||
|
|
||||||
const mockRoutes = registerRoutes(app)
|
|
||||||
mockRoutesLength = mockRoutes.mockRoutesLength
|
|
||||||
mockStartIndex = mockRoutes.mockStartIndex
|
|
||||||
|
|
||||||
console.log(chalk.magentaBright(`\n > Mock Server hot reload success! changed ${path}`))
|
|
||||||
} catch (error) {
|
|
||||||
console.log(chalk.redBright(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
import Mock from 'mockjs'
|
|
||||||
|
|
||||||
const data = Mock.mock({
|
|
||||||
'items|30': [{
|
|
||||||
id: '@id',
|
|
||||||
title: '@sentence(10, 20)',
|
|
||||||
'status|1': ['published', 'draft', 'deleted'],
|
|
||||||
author: 'name',
|
|
||||||
display_time: '@datetime',
|
|
||||||
pageviews: '@integer(300, 5000)'
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
|
|
||||||
export default [
|
|
||||||
{
|
|
||||||
url: '/vue-admin-template/table/list',
|
|
||||||
type: 'get',
|
|
||||||
response: config => {
|
|
||||||
const items = data.items
|
|
||||||
return {
|
|
||||||
code: 20000,
|
|
||||||
data: {
|
|
||||||
total: items.length,
|
|
||||||
items: items
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
84
mock/user.js
84
mock/user.js
@ -1,84 +0,0 @@
|
|||||||
|
|
||||||
const tokens = {
|
|
||||||
admin: {
|
|
||||||
token: 'admin-token'
|
|
||||||
},
|
|
||||||
editor: {
|
|
||||||
token: 'editor-token'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const users = {
|
|
||||||
'admin-token': {
|
|
||||||
roles: ['admin'],
|
|
||||||
introduction: 'I am a super administrator',
|
|
||||||
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
|
|
||||||
name: 'Super Admin'
|
|
||||||
},
|
|
||||||
'editor-token': {
|
|
||||||
roles: ['editor'],
|
|
||||||
introduction: 'I am an editor',
|
|
||||||
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
|
|
||||||
name: 'Normal Editor'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default [
|
|
||||||
// user login
|
|
||||||
{
|
|
||||||
url: '/vue-admin-template/user/login',
|
|
||||||
type: 'post',
|
|
||||||
response: config => {
|
|
||||||
const { username } = config.body
|
|
||||||
const token = tokens[username]
|
|
||||||
|
|
||||||
// mock error
|
|
||||||
if (!token) {
|
|
||||||
return {
|
|
||||||
code: 60204,
|
|
||||||
message: 'Account and password are incorrect.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
code: 20000,
|
|
||||||
data: token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// get user info
|
|
||||||
{
|
|
||||||
url: '/vue-admin-template/user/info\.*',
|
|
||||||
type: 'get',
|
|
||||||
response: config => {
|
|
||||||
const { token } = config.query
|
|
||||||
const info = users[token]
|
|
||||||
|
|
||||||
// mock error
|
|
||||||
if (!info) {
|
|
||||||
return {
|
|
||||||
code: 50008,
|
|
||||||
message: 'Login failed, unable to get user details.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
code: 20000,
|
|
||||||
data: info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// user logout
|
|
||||||
{
|
|
||||||
url: '/vue-admin-template/user/logout',
|
|
||||||
type: 'post',
|
|
||||||
response: _ => {
|
|
||||||
return {
|
|
||||||
code: 20000,
|
|
||||||
data: 'success'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@ -19,17 +19,6 @@ const port = process.env.port || process.env.npm_config_port || 9528 // dev port
|
|||||||
|
|
||||||
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
|
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
|
||||||
|
|
||||||
// let monacoLanguages = []
|
|
||||||
// const modulesFiles = require.context("monaco-languages/release/dev/", true, /\.js$/)
|
|
||||||
// modulesFiles.keys().reduce((modules, modulePath) => {
|
|
||||||
// const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1");
|
|
||||||
// if(moduleName.indexOf('contribution') === -1){
|
|
||||||
// monacoLanguages.push(moduleName.replace(/([/][^/]+)$/, ""))
|
|
||||||
// }
|
|
||||||
// // const value = modulesFiles(modulePath);
|
|
||||||
// // modules[moduleName] = value.default;
|
|
||||||
// // return modules;
|
|
||||||
// }, {});
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user