This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
2016-07-22 07:11:54 +00:00
|
|
|
import queryString from 'query-string';
|
|
|
|
|
2016-09-11 22:48:03 +00:00
|
|
|
export default function methodOverride(_options) {
|
2016-07-22 07:11:54 +00:00
|
|
|
return async function methodOverrideMiddleware(ctx, next) {
|
|
|
|
if (ctx.method === 'POST') {
|
|
|
|
ctx.body = ctx.request.body;
|
2016-07-23 19:09:50 +00:00
|
|
|
} else if (ctx.method === 'GET') {
|
2017-04-27 04:47:03 +00:00
|
|
|
ctx.method = 'POST'; // eslint-disable-line
|
2016-07-22 07:11:54 +00:00
|
|
|
ctx.body = queryString.parse(ctx.querystring);
|
|
|
|
}
|
|
|
|
return next();
|
2016-09-11 22:48:03 +00:00
|
|
|
};
|
|
|
|
}
|