funktionswerk / hapi-i18n

Translation module for hapi based on mashpie's i18n module
MIT License
39 stars 22 forks source link

Use of "@hapi/hapi" , "@hapi/joi" #29

Closed rasputtim closed 4 years ago

rasputtim commented 4 years ago

Hi, Are there plans to update the dependecies to use this package with "@hapi/hapi"? I am new to hapi. and when I tried to use this package with "@hapi/hapi" I received several errors.

kaywolter commented 4 years ago

Thanks for reporting. Can you please provide a small sample that reproduces the errors?

Cheers, Kay

rasputtim commented 4 years ago

Hi, I upgraded the package.json with the new version of @hapi/hapi and tried to run the tests. "devDependencies": { "handlebars": "^4.0.11", "@hapi/hapi": "^19.0.5", "jade": "^1.9.2", "joi": "^13.1.0", "mocha": "^4.1.0", "should": "^13.2.0", "vision": "^5.3.0" },

I received err**ors running the npm test command.

mocha --recursive test

Localization Usage of locale in hapi 1) "before all" hook 2) "after all" hook with a custom 404 handler 3) "before all" hook 4) "after all" hook

0 passing (55ms) 4 failing

1) Localization Usage of locale in hapi "before all" hook: Error: Cannot set uncompiled validation rules without configuring a validator at new module.exports (node_modules/@hapi/hoek/lib/error.js:23:19) at Object.module.exports [as assert] (node_modules/@hapi/hoek/lib/assert.js:20:11) at Object.exports.compile (node_modules/@hapi/hapi/lib/validation.js:48:10) at module.exports.internals.Route._setupValidation (node_modules/@hapi/hapi/lib/route.js:197:43) at new module.exports.internals.Route (node_modules/@hapi/hapi/lib/route.js:122:14) at internals.Server._addRoute (node_modules/@hapi/hapi/lib/server.js:498:23) at internals.Server.route (node_modules/@hapi/hapi/lib/server.js:491:22) at setupServer (test/test.js:73:10) at Context. (test/test.js:178:22) at processImmediate (internal/timers.js:439:21)

2) Localization Usage of locale in hapi "after all" hook: TypeError: Cannot read property 'stop' of undefined at Context. (test/test.js:183:32) at processImmediate (internal/timers.js:439:21)

3) Localization with a custom 404 handler "before all" hook: Error: Cannot set uncompiled validation rules without configuring a validator at new module.exports (node_modules/@hapi/hoek/lib/error.js:23:19) at Object.module.exports [as assert] (node_modules/@hapi/hoek/lib/assert.js:20:11) at Object.exports.compile (node_modules/@hapi/hapi/lib/validation.js:48:10) at module.exports.internals.Route._setupValidation (node_modules/@hapi/hapi/lib/route.js:197:43) at new module.exports.internals.Route (node_modules/@hapi/hapi/lib/route.js:122:14) at internals.Server._addRoute (node_modules/@hapi/hapi/lib/server.js:498:23) at internals.Server.route (node_modules/@hapi/hapi/lib/server.js:491:22) at setupServer (test/test.js:73:10) at Context. (test/test.js:438:22) at processImmediate (internal/timers.js:439:21)

4) Localization with a custom 404 handler "after all" hook: TypeError: Cannot read property 'stop' of undefined at Context. (test/test.js:468:32) at processImmediate (internal/timers.js:439:21)

npm ERR! Test failed. See above for more details.

rasputtim commented 4 years ago

Hi,

I would appreciate if it was possible to upgrade the dependencies to the version 19.0.5 as all my project is running under this version. And I need to add i18n support to it.

After I added a validator in the test.js.

I receive this error:

(node:18064) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 400) 11) must assure correct localization when processing requests concurrently with a custom 404 handler Debug: internal, implementation, error TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type object at validateString (internal/validators.js:112:11) at Url.parse (url.js:155:3) at Object.urlParse [as parse] (url.js:150:13) at guessLanguage (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/i18n/i18n.js:663:26) at Object.i18nInit [as init] (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/i18n/i18n.js:182:7) at /home/dono/projetos/Nodejs/happi/hapi-i18n-master/index.js:51:12 at exports.Manager.execute (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/hapi/lib/toolkit.js:60:33) at Request._invoke (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/hapi/lib/request.js:392:55) at Request._onRequest (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/hapi/lib/request.js:283:41) at Request._execute (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/hapi/lib/request.js:265:24) at /home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/hapi/lib/core.js:529:21 at /home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/shot/lib/index.js:60:27 at module.exports.internals.Request.prepare (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/shot/lib/request.js:93:20) at /home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/shot/lib/index.js:60:13 at new Promise () at Object.exports.inject (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/shot/lib/index.js:55:12) at internals.Server.inject (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/@hapi/hapi/lib/server.js:324:32) at Context. (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/test/test.js:472:37) at callFn (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runnable.js:354:21) at Test.Runnable.run (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runnable.js:346:7) at Runner.runTest (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runner.js:442:10) at /home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runner.js:560:12 at next (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runner.js:356:14) at /home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runner.js:366:7 at next (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runner.js:290:14) at Immediate._onImmediate (/home/dono/projetos/Nodejs/happi/hapi-i18n-master/node_modules/mocha/lib/runner.js:334:5) at processImmediate (internal/timers.js:439:21) 12) is still available when handling missing routes

2 passing (6s) 12 failing

rasputtim commented 4 years ago

it seems that the request.url is now a Symbol (inversion 19.0.4 of @hapi/hapi) instead of an object and the url.parse method does not handle a Symbol as required in the line 663 of the i18n.js file. var urlObj = url.parse(request.url, true); If it is right I do not know how could this be fixed.

kaywolter commented 4 years ago

I created new PR for support of Hapi 19+, you can check it out if it works for you: https://github.com/funktionswerk/hapi-i18n/pull/30

Unfortunately, mashpie/i18n-node needs to be updated as well to support WHATWG URL API. I updated the module and created a pull request, hope they will merge it soon: https://github.com/mashpie/i18n-node/pull/425

rasputtim commented 4 years ago

thanks a lot. I managed it to work with the modifications you suggested in the mashpie package and in the file test.js. the only think i did different in the test.js file was the user of server.validator(Joi); instead of: payload: Joi.object({ param: Joi.string().required() },

kaywolter commented 4 years ago

New version 3.0.0 is released. I added some further changes to update/remove dependencies. Please close issue if everything works for you :)