Cannot expose HTTP API

I’m writing an extension to add some vendor-specific capabilities to my site, and I’m running up against a rather strange error. I added a http-functions.js and even the pre-generated contents are throwing the following error:

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

Where am I supposed to put the API file to be able to run the code within?

For http-functions they’re not imported but rather called via HTTP GET / POST requests as they’re a way to expose a REST API on your site. They’re only used if there’s a need to consume a site’s functionality off-site.

The exposed endpoints are defined with the naming convention mentioned here:

I used the pre-generated contents without further modification, but it was still throwing the same error when I tried to call the function via its URL at /_functions-dev/multiply or /_functions/multiply.
However, your comment that these are supposed to be used when “exposing functionality to third parties” does tell me that this is not the path I need to take. So thanks for clearing that up!

That said, after some more thought, I don’t quite understand why the Wix infrastructure responds with a 404 when it’s not a question of the resource not existing, but one of an error being thrown while attempting to serve the resource, which would probably be a status in the 5XX range…

I was thinking about this and I believe it’s because of the order of operations which is probably something like:

  1. Check if endpoint exists
  2. Attempt to serve resource
  3. Serve resource

Step 1 fails so that’s a 404 in this case because it didn’t exist.