fix(query): use qs for querystring parsing

This commit is contained in:
Mahdi Dibaiee 2016-03-02 12:13:27 +03:30
parent 45d991d1e9
commit 00e8e89767
2 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "hapi-sequelize-crud", "name": "hapi-sequelize-crud",
"version": "1.5.1", "version": "1.5.2",
"description": "Hapi plugin that automatically generates RESTful API for CRUD", "description": "Hapi plugin that automatically generates RESTful API for CRUD",
"main": "build/index.js", "main": "build/index.js",
"config": { "config": {

View File

@ -1,4 +1,6 @@
import crud, { associations } from './crud'; import crud, { associations } from './crud';
import url from 'url';
import qs from 'qs';
const register = (server, options = {}, next) => { const register = (server, options = {}, next) => {
options.prefix = options.prefix || ''; options.prefix = options.prefix || '';
@ -6,6 +8,20 @@ const register = (server, options = {}, next) => {
let db = server.plugins['hapi-sequelize'].db; let db = server.plugins['hapi-sequelize'].db;
let models = db.sequelize.models; 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)) { for (let modelName of Object.keys(models)) {
let model = models[modelName]; let model = models[modelName];
let { plural, singular } = model.options.name; let { plural, singular } = model.options.name;