Wix:加载 Web 模块 backend/http-functions.js 时出错:找不到模块“backend/http-functions.js”

问题描述 投票:0回答:1

我正在尝试使用本教程在 Wix 上公开 API 端点: https://www.wix.com/velo/reference/wix-http-functions

我在这里定义了我的 http-functions.js 文件:

这是 http-functions.js 中的内容:

import { ok, notFound, serverError } from 'wix-http-functions';

export function get_myFunction(request) {
  let options = {
    headers: {
      'Content-Type': 'text/plain',  // Change content type to plain text
      'Access-Control-Allow-Origin': '*',  // Allow requests from any origin
      'Access-Control-Allow-Methods': 'GET',  // Specify allowed HTTP methods
    },
    body: 'Hello World'  // Set the response body to "Hello World"
  };
  
  return ok(options);  // Return the response
}

当我尝试使用邮递员到达终点时 https://.wixsite.com//_functions-dev/get_myFunction 使用开发预览版时,我在 wix 控制台中收到此错误:

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

我尝试过发布并尝试不使用 -dev 的链接,没有任何区别。

我也尝试过不使用 cors 标头。

我也在浏览器中尝试了该链接。

http 请求返回了带有以下标头的 404: x-wix-代码-用户错误详细信息 {“isUserError”:true,“code”:“MODULE_NOT_FOUND”}

http cors wix velo
1个回答
0
投票

错误在于我,

我的“http-functions.js”是在 public/http-functions.js 而不是 backend/http-functions.js 定义的

© www.soinside.com 2019 - 2024. All rights reserved.