diff --git a/package.json b/package.json index a6ce524..a84e65f 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/index.js b/src/index.js index 7fd9b93..288e501 100644 --- a/src/index.js +++ b/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;