Moved to using GET and caching with SW
This commit is contained in:
@ -88,6 +88,7 @@
|
||||
"normalizr": "2.0.1",
|
||||
"pg": "6.0.1",
|
||||
"pg-hstore": "2.3.2",
|
||||
"query-string": "^4.2.2",
|
||||
"querystring": "0.2.0",
|
||||
"randomstring": "1.1.5",
|
||||
"react": "15.1.0",
|
||||
|
@ -9,7 +9,7 @@ import { User, Team } from '../models';
|
||||
const router = new Router();
|
||||
|
||||
router.post('auth.slack', async (ctx) => {
|
||||
const { code } = ctx.request.body;
|
||||
const { code } = ctx.body;
|
||||
ctx.assertPresent(code, 'code is required');
|
||||
|
||||
const body = {
|
||||
|
@ -14,7 +14,7 @@ router.post('atlases.create', auth(), async (ctx) => {
|
||||
name,
|
||||
description,
|
||||
type,
|
||||
} = ctx.request.body;
|
||||
} = ctx.body;
|
||||
ctx.assertPresent(name, 'name is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
@ -32,7 +32,7 @@ router.post('atlases.create', auth(), async (ctx) => {
|
||||
});
|
||||
|
||||
router.post('atlases.info', auth(), async (ctx) => {
|
||||
let { id } = ctx.request.body;
|
||||
let { id } = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
@ -79,7 +79,7 @@ router.post('atlases.list', auth(), pagination(), async (ctx) => {
|
||||
});
|
||||
|
||||
router.post('atlases.updateNavigationTree', auth(), async (ctx) => {
|
||||
let { id, tree } = ctx.request.body;
|
||||
let { id, tree } = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
|
@ -13,7 +13,7 @@ const router = new Router();
|
||||
|
||||
// FIXME: This really needs specs :/
|
||||
router.post('documents.info', auth({ require: false }), async (ctx) => {
|
||||
let { id } = ctx.request.body;
|
||||
let { id } = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
const document = await Document.findOne({
|
||||
@ -44,7 +44,7 @@ router.post('documents.info', auth({ require: false }), async (ctx) => {
|
||||
});
|
||||
|
||||
router.post('documents.search', auth(), async (ctx) => {
|
||||
let { query } = ctx.request.body;
|
||||
let { query } = ctx.body;
|
||||
ctx.assertPresent(query, 'query is required');
|
||||
|
||||
const user = await ctx.state.user;
|
||||
@ -86,7 +86,7 @@ router.post('documents.create', auth(), async (ctx) => {
|
||||
title,
|
||||
text,
|
||||
parentDocument,
|
||||
} = ctx.request.body;
|
||||
} = ctx.body;
|
||||
ctx.assertPresent(atlas, 'atlas is required');
|
||||
ctx.assertPresent(title, 'title is required');
|
||||
ctx.assertPresent(text, 'text is required');
|
||||
@ -138,7 +138,7 @@ router.post('documents.update', auth(), async (ctx) => {
|
||||
id,
|
||||
title,
|
||||
text,
|
||||
} = ctx.request.body;
|
||||
} = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
ctx.assertPresent(title, 'title is required');
|
||||
ctx.assertPresent(text, 'text is required');
|
||||
@ -174,7 +174,7 @@ router.post('documents.update', auth(), async (ctx) => {
|
||||
router.post('documents.delete', auth(), async (ctx) => {
|
||||
let {
|
||||
id,
|
||||
} = ctx.request.body;
|
||||
} = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
|
@ -10,6 +10,7 @@ import collections from './collections';
|
||||
import documents from './documents';
|
||||
|
||||
import validation from './validation';
|
||||
import methodOverride from '../middlewares/methodOverride';
|
||||
|
||||
const api = new Koa();
|
||||
const router = new Router();
|
||||
@ -40,6 +41,7 @@ api.use(async (ctx, next) => {
|
||||
});
|
||||
|
||||
api.use(bodyParser());
|
||||
api.use(methodOverride());
|
||||
api.use(validation());
|
||||
|
||||
router.use('/', auth.routes());
|
||||
|
@ -16,7 +16,7 @@ router.post('user.info', auth(), async (ctx) => {
|
||||
});
|
||||
|
||||
router.post('user.s3Upload', auth(), async (ctx) => {
|
||||
let { filename, kind, size } = ctx.request.body;
|
||||
let { filename, kind, size } = ctx.body;
|
||||
ctx.assertPresent(filename, 'filename is required');
|
||||
ctx.assertPresent(kind, 'kind is required');
|
||||
ctx.assertPresent(size, 'size is required');
|
||||
|
13
server/middlewares/methodOverride.js
Normal file
13
server/middlewares/methodOverride.js
Normal file
@ -0,0 +1,13 @@
|
||||
import queryString from 'query-string';
|
||||
|
||||
export default function methodOverride(options) {
|
||||
return async function methodOverrideMiddleware(ctx, next) {
|
||||
if (ctx.method === 'POST') {
|
||||
ctx.body = ctx.request.body;
|
||||
} else {
|
||||
ctx.method= 'POST';
|
||||
ctx.body = queryString.parse(ctx.querystring);
|
||||
}
|
||||
return next();
|
||||
}
|
||||
};
|
@ -61,7 +61,7 @@ Cache.prototype.addAll||(Cache.prototype.addAll=function(t){function e(t){this.n
|
||||
global.toolbox.router.get(/\/static\//, global.toolbox.cacheFirst);
|
||||
|
||||
// API get calls
|
||||
global.toolbox.router.post(/\/api\/[\w\.]+/, global.toolbox.networkFirst);
|
||||
global.toolbox.router.get(/\/api\/[\w\.]+/, global.toolbox.networkFirst);
|
||||
|
||||
global.toolbox.router.default = global.toolbox.networkFirst;
|
||||
|
||||
|
@ -14,7 +14,7 @@ class ApiClient {
|
||||
let modifiedPath;
|
||||
|
||||
if (method === 'GET') {
|
||||
modifiedPath = path + this.constructQueryString(data);
|
||||
modifiedPath = `${path}?${this.constructQueryString(data)}`;
|
||||
} else if (method === 'POST' || method === 'PUT') {
|
||||
body = JSON.stringify(data);
|
||||
}
|
||||
@ -78,7 +78,7 @@ class ApiClient {
|
||||
}
|
||||
|
||||
post = (path, data) => {
|
||||
return this.fetch(path, 'POST', data);
|
||||
return this.fetch(path, 'GET', data);
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
Reference in New Issue
Block a user