fix(query): use qs
for querystring parsing
This commit is contained in:
parent
45d991d1e9
commit
00e8e89767
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hapi-sequelize-crud",
|
||||
"version": "1.5.1",
|
||||
"version": "1.5.2",
|
||||
"description": "Hapi plugin that automatically generates RESTful API for CRUD",
|
||||
"main": "build/index.js",
|
||||
"config": {
|
||||
|
16
src/index.js
16
src/index.js
@ -1,4 +1,6 @@
|
||||
import crud, { associations } from './crud';
|
||||
import url from 'url';
|
||||
import qs from 'qs';
|
||||
|
||||
const register = (server, options = {}, next) => {
|
||||
options.prefix = options.prefix || '';
|
||||
@ -6,6 +8,20 @@ const register = (server, options = {}, next) => {
|
||||
let db = server.plugins['hapi-sequelize'].db;
|
||||
let models = db.sequelize.models;
|
||||
|
||||
const onRequest = function (request, reply) {
|
||||
const uri = request.raw.req.url;
|
||||
const parsed = url.parse(uri, false);
|
||||
parsed.query = qs.parse(parsed.query);
|
||||
request.setUrl(parsed);
|
||||
|
||||
return reply.continue();
|
||||
};
|
||||
|
||||
server.ext({
|
||||
type: 'onRequest',
|
||||
method: onRequest
|
||||
});
|
||||
|
||||
for (let modelName of Object.keys(models)) {
|
||||
let model = models[modelName];
|
||||
let { plural, singular } = model.options.name;
|
||||
|
Loading…
Reference in New Issue
Block a user