Open TheOwlDude opened 8 months ago
node.js
20.11.1
21.3.3
Both standalone (local development) and as an AWS lambda handler. Both exhibit the problem
We have very simple configuration.
This is the server config.
const serverConfig: Hapi.ServerOptions = { port: process.env.SERVICE_PORT || 8400, routes: { cors: { origin: ['*'], additionalHeaders: ['x-api-key'], }, validate: { failAction: handleError, options: { abortEarly: false, }, }, json: { space: 4, } }, };
We don't create route objects per route we just add these lines to classes that implement Controller
@controller('/v1/route') export class ExampleController1 implements Controller { public baseUrl!: string; public routes!: () => Array; }
We configure the routes on the server like this
export default class Router {
public static async loadRoutes(server: Hapi.Server, dependencies : ServiceDependencies): Promise { server.route([ ...new ExampleController1().routes(), ...new ExampleController2().routes(), ]); }
When our route handlers are called it is always the case that request.query == {} regardless of the query parameters added to the url.
It would be lovely if you could explain how we can fix our configuration so that we receive query string parameters in the request object.
@TheOwlDude Hard to tell what's going on and how Hapi is being used without an example to run. Is there a CodePen you can send?
Runtime
node.js
Runtime version
20.11.1
Module version
21.3.3
Used with
Both standalone (local development) and as an AWS lambda handler. Both exhibit the problem
Any other relevant information
We have very simple configuration.
This is the server config.
const serverConfig: Hapi.ServerOptions = { port: process.env.SERVICE_PORT || 8400, routes: { cors: { origin: ['*'], additionalHeaders: ['x-api-key'], }, validate: { failAction: handleError, options: { abortEarly: false, }, }, json: { space: 4, } }, };
We don't create route objects per route we just add these lines to classes that implement Controller
@controller('/v1/route') export class ExampleController1 implements Controller { public baseUrl!: string; public routes!: () => Array;
}
We configure the routes on the server like this
export default class Router {
public static async loadRoutes(server: Hapi.Server, dependencies : ServiceDependencies): Promise {
server.route([
...new ExampleController1().routes(),
...new ExampleController2().routes(),
]);
}
When our route handlers are called it is always the case that request.query == {} regardless of the query parameters added to the url.
How can we help?
It would be lovely if you could explain how we can fix our configuration so that we receive query string parameters in the request object.