我正在创建一个在后端使用Deno 的React Native/Expo 应用程序。我在后端创建了一个 API,可以在 localhost:4000 上本地运行。但是,当我尝试使用 fetch 调用 Expo 应用程序中的 API 时,我不断收到错误消息
[Unhandled promise rejection: TypeError: Network request failed] at node_modules/whatwg-fetch/dist/fetch.umd.js:535:17 in setTimeout$argument_0
Run Code Online (Sandbox Code Playgroud)
这是我设置后端的方法
import { Application } from "https://deno.land/x/oak/mod.ts";
import { oakCors } from "https://deno.land/x/cors/mod.ts";
import { APP_HOST, APP_PORT } from "./config.ts";
import router from "./routes.ts";
import _404 from "./controllers/404.ts";
import errorHandler from "./controllers/errorHandler.ts";
const app = new Application();
app.use(oakCors());
app.use(errorHandler);
app.use(router.routes());
app.use(router.allowedMethods());
app.use(_404);
console.log(`Listening on port:${APP_PORT}...`);
Run Code Online (Sandbox Code Playgroud)
以及我如何使用 fetch 调用 API
const App = () => …Run Code Online (Sandbox Code Playgroud)