Hi there…I need some help badly. I have a static website based on html and plain javascript. I need to add some backend functionality so I have moved my project to glitch. Created a Fastify server app and integrated the url’s which is working fine.
I have a form submission in checkout page html upon success will land in confirmation html. My node js api is not able to read the request.body. I have implemented the middleware function also. Below is the snippet from server.js, Any help is appreciated.
fastify.register(require(‘fastify-raw-body’), {
field: ‘rawBody’, // change the default request.rawBody property name
global: false, // add the rawBody to every request. Default true
encoding: ‘utf8’, // set it to false to set rawBody as a Buffer Default utf8
runFirst: true, // get the body before any preParsing hook change/uncompress it. Default false
routes: // array of routes, global
will be ignored, wildcard routes not supported
});
// A POST route to handle form submissions
fastify.post(“/pages/checkout/confirmation”, {
config: {
// add the rawBody to this route. if false, rawBody will be disabled when global is true
rawBody: true
},
handler (request, reply) {
let params = null;
console.log("### ");
console.log(request.rawBody);
//console.log(`${JSON.stringify(request)}`);
// request.body.paramName <-- a form post example
return reply.view(
"/public/resources/checkout/checkoutConfirmation.html", params);
}
});