Module Not Found Error for Backend HTTP Function on Wix

Hello Wix Community,

I’m encountering a persistent “Module Not Found” error when trying to set up an HTTP function for IPN handling with PayTabs. Despite ensuring that my file is named correctly (http-functions.js) and located in the Backend section, the Wix system logs still show an attempt to load a non-existent .js file. Here’s the error message I receive:

"Error loading web module backend/http-functions.js: Cannot find module 'backend/http-functions.js' Require stack: - /user-code/stubmodule-that-does-the-require.js - /cloud-runtime-code/node_modules/scoped-require/index.js - /cloud-runtime-code/packages/elementory/cloud-runtime/factories.js - /cloud-runtime-code/packages/elementory/cloud-runtime/create-app.js - /cloud-runtime-code/packages/elementory/cloud-runtime/cloud-grid-runner.js"

I’ve tried the following steps to resolve the issue:

  • Renamed the file to .jsw from .js. Same error.
  • Ensured that the file is placed in the Backend directory.
  • Checked for any caching issues and waited for changes to propagate.
  • Synced my site after making changes in Dev mode.

Despite these efforts, the error persists. Has anyone encountered a similar issue or can offer insights into what might be going wrong? Any help would be greatly appreciated!

Thank you!

I assume you are using http-functions the first time ???

If so, please read the following post, which will teach you how to do and where to pay attention to…

2 Likes

Yup found it the problem. Thanks for the info!

Not sure if you can help with this but if you don’t mind I’m also having a problem with comparing the signatures together from the payment gateway API and the website.

I wrote all this code after hours and hours of research (never done it before as you said). I added console logs to help me with every step to debug the problem, it seems the signature that I’m retrieving from the header comes back as null.

import { ok, badRequest, serverError } from 'wix-http-functions';
import wixSecretsBackend from 'wix-secrets-backend';
import { createHmac } from 'crypto';

export async function post_paymentCallback(request) {
    console.log("Received IPN callback request");
    
    // Retrieve the server key from Wix Secrets Manager
    let serverKey;
    try {
        serverKey = await wixSecretsBackend.getSecret("MEPS_SERVER_KEY");
        console.log("Server key retrieved successfully");
    } catch (error) {
        console.error("Error retrieving server key:", error);
        return serverError({ "body": "Error retrieving server key" });
    }

    // Extract the signature from the request headers
    const requestSignature = request.headers["Signature"]; // Lowercase 's' to ensure compatibility
    console.log("Request signature extracted:", requestSignature);
    
    if (!requestSignature) {
        console.log("No signature found in the request headers.");
        return badRequest({ "body": "No signature provided in the request headers." });
    }

    try {
        // Read the request body
        const requestBody = await request.body.text();
        console.log("Request body received:", requestBody);
        
        // Generate an HMAC signature of the request body using the server key
        const calculatedSignature = createHmac('sha256', serverKey)
                                    .update(requestBody)
                                    .digest('hex');
        console.log("Calculated signature:", calculatedSignature);

        // Compare the signature from MEPS with the signature you've generated
        if (calculatedSignature === requestSignature) {
            console.log("Signature match confirmed");
            // If the signature matches, parse the IPN data and handle it
            const ipnData = JSON.parse(requestBody);
            console.log("IPN data parsed:", ipnData);
            // Implement your logic to process the IPN data here

            // Respond to MEPS with 200 OK to acknowledge receipt of the notification
            return ok({ "body": "Signature verified successfully" });
        } else {
            console.log("Signature mismatch detected");
            // If the signature does not match, respond with 500 Server Error
            return serverError({ "body": "Invalid signature" });
        }
    } catch (error) {
        // Log any errors for debugging
        console.error('Error processing payment callback:', error);
        // Respond with 500 Server Error
        return serverError({ "body": `Error processing request: ${error.message}` });
    }
}

Many thanks in advance

Show all LOG-HISTORY when running your code (screenshot)

HIDE SENSITIVE DATA IF SENSITIVE DATA IS INCLUDED INSIDE YOUR LOGS!

Wow I followed ur thread russian-dima - that checklist and back-and-forth with Shan was very helpful. Basically all the mistakes I was making

1 Like

Try to concentrate on the last working log you get to debug your issue.

At which codeline / code-log do break your code?

hi guys i having same problem, can i know wht doing wrong pls i struggling, i dont getting it