This commit is contained in:
2019-06-07 15:59:39 +08:00
parent a6fd705801
commit 118b8f9d3a
8 changed files with 1198 additions and 11098 deletions

View File

@ -1,31 +1,39 @@
export let Get = (ctx) => {
export const Get = (ctx, next) => {
ctx.body = {
result: 'get',
name: ctx.params.name,
para: ctx.query
}
next()
}
export let Post = async (ctx) => {
export const Post = async (ctx, next) => {
ctx.body = {
result: 'post',
name: ctx.params.name,
para: ctx.request.body
}
next()
}
export let Put = (ctx) => {
export const Put = (ctx, next) => {
ctx.body = {
result: 'put',
name: ctx.params.name,
para: ctx.request.body
}
next()
}
export let Delete = (ctx) => {
export const Delete = (ctx, next) => {
ctx.body = {
result: 'delete',
name: ctx.params.name,
para: ctx.request.body
}
next()
}

View File

@ -12,7 +12,7 @@ const publicKey = fs.readFileSync(path.join(__dirname, '../../publicKey.pub'))
/**
* 检查授权是否合法
*/
export let CheckAuth = (ctx) => {
const CheckAuth = (ctx, next) => {
let token = ctx.request.header.authorization
try {
let decoded = jwt.verify(token.substr(7), publicKey)
@ -39,11 +39,11 @@ export let CheckAuth = (ctx) => {
}
}
export let Post = (ctx) => {
export const Post = (ctx, next) => {
switch (ctx.params.action) {
case 'check':
return CheckAuth(ctx).then(result => { ctx.body = result })
return CheckAuth(ctx).then(result => { ctx.body = result; next() })
default:
return CheckAuth(ctx).then(result => { ctx.body = result })
return CheckAuth(ctx).then(result => { ctx.body = result; next() })
}
}

View File

@ -1,2 +1,9 @@
let requireDirectory = require('require-directory')
module.exports = requireDirectory(module)
import upload from './upload'
import * as api from './api'
import * as auth from './auth'
export default {
upload,
api,
auth
}