upload dependencies
This commit is contained in:
parent
44bf741c62
commit
7110c61b78
21
.babelrc
21
.babelrc
@ -1,4 +1,21 @@
|
||||
{
|
||||
"presets": ["es2015", "stage-2"],
|
||||
"plugins": ["transform-runtime"]
|
||||
"presets": [
|
||||
["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}]
|
||||
],
|
||||
"env": {
|
||||
"test": {
|
||||
"presets": [
|
||||
["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
},
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
build/*.js
|
||||
assets/*.js
|
||||
test/**/*.js
|
@ -1,7 +1,8 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parserOptions: {
|
||||
ecmaVersion: 8, //指定ECMAScript支持的版本,6为ES6,这里为了兼容async和await,设置为8
|
||||
parser: 'babel-eslint',
|
||||
ecmaVersion: 2017, //指定ECMAScript支持的版本,6为ES6,这里为了兼容async和await,设置为2017
|
||||
sourceType: 'module'
|
||||
},
|
||||
extends: 'standard',
|
||||
|
11
LICENSE
Normal file
11
LICENSE
Normal file
@ -0,0 +1,11 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
13
README.md
13
README.md
@ -3,7 +3,7 @@ Koa2 RESTful API 服务器脚手架
|
||||
|
||||
这是一个基于Koa2的轻量级RESTful API Server脚手架,支持ES6。
|
||||
|
||||
**注意:因升级Koa版本至2.3.0,为配合相应的依赖项,故需要Node.js版本大于等于v8.0.0(建议v9.9.0),NPM大于等于v5.0.0。建议使用yarn代替npm。**
|
||||
**注意:**因升级Koa版本至2.3.0+,为配合相应的依赖项,故需要Node.js版本大于等于v8.0.0(建议v11.13.0),NPM大于等于v5.0.0。建议使用yarn代替npm。
|
||||
|
||||
约定使用JSON格式传输数据,POST、PUT、DELET方法支持的Content-Type为`application/x-www-form-urlencoded、multipart/form-data、application/json`可配置支持跨域。非上传文件推荐application/x-www-form-urlencoded。通常情况下返回application/json格式的JSON数据。
|
||||
|
||||
@ -11,19 +11,18 @@ Koa2 RESTful API 服务器脚手架
|
||||
|
||||
此脚手架只安装了一些和Koa2不冲突的搭建RESTful API Server的必要插件,附带每一个插件的说明。采用ESlint进行语法检查。
|
||||
|
||||
因此脚手架主要提供RESTful API,故暂时不考虑前端静态资源处理,只提供静态资源访问的基本方法便于访问用户上传到服务器的图片等资源。基本目录结构与vue-cli保持一致,可配合React、AngularJS、Vue.js等前端框架使用。在Cordova/PhoneGap中使用时需要开启跨域功能。
|
||||
因此脚手架主要提供RESTful API,故暂时不考虑前端静态资源处理,只提供静态资源访问的基本方法便于访问用户上传到服务器的图片等资源。基本目录结构与vue-cli保持一致,可配合React、AngularJS、Vue.js等前端框架使用。在Cordova/PhoneGap、Electron中使用时需要开启跨域功能。
|
||||
|
||||
**免责声明:** 此脚手架仅为方便开发提供基础环境,任何人或组织均可随意克隆使用,使用引入的框架需遵循原作者规定的相关协议(部分框架列表及来源地址在下方)。采用此脚手架产生的任何后果请自行承担,本人不对此脚手架负任何法律责任,使用即代表同意此条。
|
||||
|
||||
目前暂未加入软件测试模块,下一个版本会加入该功能并提供集成方案。建议自行集成jest。
|
||||
|
||||
|
||||
基于Vue 2,Webpack 4,Koa 2的SSR脚手架:[https://github.com/yi-ge/Vue-SSR-Koa2-Scaffold](https://github.com/yi-ge/Vue-SSR-Koa2-Scaffold)。
|
||||
**基于Vue 2,Webpack 4,Koa 2的SSR脚手架:**[https://github.com/yi-ge/Vue-SSR-Koa2-Scaffold](https://github.com/yi-ge/Vue-SSR-Koa2-Scaffold)。
|
||||
|
||||
开发使用说明
|
||||
------------
|
||||
|
||||
```
|
||||
```bash
|
||||
$ git clone https://github.com/yi-ge/koa2-API-scaffold.git
|
||||
|
||||
$ cd mv koa2-API-scaffold
|
||||
@ -653,6 +652,10 @@ request.post('/api').form({key:'value'}), function(err,httpResponse,body){ /* ..
|
||||
|
||||
更新说明
|
||||
--------
|
||||
*v1.0.0 2019年04月07日21:19:59*
|
||||
|
||||
1. 升级依赖项版本(node11.13.0)。
|
||||
2. 添加Jest。
|
||||
|
||||
*v0.2.6 2018年03月24日22:16:43*
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
require('babel-register')
|
||||
require('@babel/register')
|
||||
require('../src/app')
|
||||
|
12
gulpfile.js
12
gulpfile.js
@ -12,7 +12,7 @@ function lintOne (aims) {
|
||||
console.log('ESlint:' + aims)
|
||||
console.time('Finished eslint')
|
||||
return gulp.src(aims)
|
||||
.pipe(eslint({configFile: './.eslintrc.js'}))
|
||||
.pipe(eslint({ configFile: './.eslintrc.js' }))
|
||||
.pipe(eslint.format(friendlyFormatter))
|
||||
.pipe(eslint.results(results => {
|
||||
// Called once for all ESLint results.
|
||||
@ -25,7 +25,7 @@ function lintOne (aims) {
|
||||
|
||||
gulp.task('ESlint', () => {
|
||||
return gulp.src(['src/**/*.js', '!node_modules/**'])
|
||||
.pipe(eslint({configFile: './.eslintrc.js'}))
|
||||
.pipe(eslint({ configFile: './.eslintrc.js' }))
|
||||
.pipe(eslint.format(friendlyFormatter))
|
||||
// .pipe(eslint.failAfterError())
|
||||
.pipe(eslint.results(results => {
|
||||
@ -36,7 +36,7 @@ gulp.task('ESlint', () => {
|
||||
}))
|
||||
})
|
||||
|
||||
gulp.task('ESlint_nodemon', ['ESlint'], function () {
|
||||
gulp.task('ESlint_nodemon', gulp.series('ESlint', function () {
|
||||
var stream = nodemon({
|
||||
script: 'build/dev-server.js',
|
||||
execMap: {
|
||||
@ -62,7 +62,7 @@ gulp.task('ESlint_nodemon', ['ESlint'], function () {
|
||||
console.error('Application has crashed!\n')
|
||||
// stream.emit('restart', 20) // restart the server in 20 seconds
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
||||
gulp.task('nodemon', function () {
|
||||
return nodemon({
|
||||
@ -79,6 +79,6 @@ gulp.task('nodemon', function () {
|
||||
})
|
||||
})
|
||||
|
||||
gulp.task('default', ['ESlint', 'ESlint_nodemon'], function () {
|
||||
gulp.task('default', gulp.series('ESlint', 'ESlint_nodemon', function () {
|
||||
// console.log('ESlin检查完成')
|
||||
})
|
||||
}))
|
||||
|
62
package.json
62
package.json
@ -2,44 +2,50 @@
|
||||
"name": "koa2-API-scaffold",
|
||||
"version": "1.0.0",
|
||||
"description": "Koa2 RESTful API 服务器的脚手架",
|
||||
"author": "轶哥 <a@wyr.me>",
|
||||
"author": "yi-ge <a@wyr.me>",
|
||||
"license": "WTFPL",
|
||||
"scripts": {
|
||||
"start": "gulp nodemon",
|
||||
"dev": "gulp",
|
||||
"build": "babel src -d dist",
|
||||
"production": "node dist/app.js"
|
||||
"production": "node dist/app.js",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsonwebtoken": "^8.1.0",
|
||||
"koa": "^2.3.0",
|
||||
"koa-body": "^2.5.0",
|
||||
"koa-compose": "^4.0.0",
|
||||
"koa-jwt": "^3.2.2",
|
||||
"koa-router": "^7.2.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"koa": "^2.7.0",
|
||||
"koa-body": "^4.1.0",
|
||||
"koa-compose": "^4.1.0",
|
||||
"koa-jwt": "^3.5.1",
|
||||
"koa-router": "^7.4.0",
|
||||
"koa-static2": "^0.1.8",
|
||||
"nodemailer": "^4.3.0",
|
||||
"promise-mysql": "^3.1.1",
|
||||
"nodemailer": "^6.1.0",
|
||||
"promise-mysql": "^3.3.1",
|
||||
"require-directory": "^2.1.1",
|
||||
"sequelize": "^4.16.1"
|
||||
"sequelize": "^5.2.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-plugin-transform-runtime": "^6.22.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"babel-register": "^6.26.0",
|
||||
"eslint": "^4.9.0",
|
||||
"eslint-config-standard": "^11.0.0-beta.0",
|
||||
"eslint-friendly-formatter": "^3.0.0",
|
||||
"eslint-plugin-html": "^4.0.1",
|
||||
"eslint-plugin-import": "^2.8.0",
|
||||
"eslint-plugin-node": "^5.2.1",
|
||||
"eslint-plugin-promise": "^3.6.0",
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-eslint": "^4.0.0",
|
||||
"gulp-nodemon": "^2.2.1",
|
||||
"koa-logger": "^3.1.0"
|
||||
"@babel/core": "^7.4.3",
|
||||
"@babel/plugin-external-helpers": "^7.2.0",
|
||||
"@babel/plugin-transform-runtime": "^7.4.3",
|
||||
"@babel/preset-env": "^7.4.3",
|
||||
"@babel/register": "^7.4.0",
|
||||
"@babel/runtime": "^7.4.3",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-config-standard": "^12.0.0",
|
||||
"eslint-friendly-formatter": "^4.0.1",
|
||||
"eslint-plugin-html": "^5.0.3",
|
||||
"eslint-plugin-import": "^2.16.0",
|
||||
"eslint-plugin-jest": "^22.4.1",
|
||||
"eslint-plugin-node": "^8.0.1",
|
||||
"eslint-plugin-promise": "^4.1.1",
|
||||
"eslint-plugin-standard": "^4.0.0",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-eslint": "^5.0.0",
|
||||
"gulp-nodemon": "^2.4.2",
|
||||
"jest": "^24.7.1",
|
||||
"koa-logger": "^3.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 7.8.0",
|
||||
|
@ -34,7 +34,7 @@ app
|
||||
.use(jwt({ secret: publicKey }).unless({ path: [/^\/public|\/user\/login|\/assets/] }))
|
||||
.use(KoaBody({
|
||||
multipart: true,
|
||||
strict: false,
|
||||
parsedMethods: ['POST', 'PUT', 'PATCH', 'GET', 'HEAD', 'DELETE'], // parse GET, HEAD, DELETE requests
|
||||
formidable: {
|
||||
uploadDir: path.join(__dirname, '../assets/uploads/tmp')
|
||||
},
|
||||
|
6
test/index.test.js
Normal file
6
test/index.test.js
Normal file
@ -0,0 +1,6 @@
|
||||
import app from '../src/app'
|
||||
|
||||
// Example
|
||||
test('isObject', () => {
|
||||
expect(typeof app).toBe('object')
|
||||
})
|
Loading…
Reference in New Issue
Block a user