我正在使用 React 和 Nextjs,并在端口 3001 上運(yùn)行 Express 后端。我正在嘗試讓我的注冊頁面將信息發(fā)布到數(shù)據(jù)庫,但我收到了一組錯(cuò)誤編輯 - 修復(fù) CORS 問題,發(fā)布到數(shù)據(jù)庫時(shí)仍有問題編輯 - 這是新的錯(cuò)誤:POST http://localhost:3001/users/signup 404 (Not Found)這個(gè)未捕獲的承諾錯(cuò)誤:createError.js:16 Uncaught (in promise) Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:83)我認(rèn)為問題出在 axios 帖子上,但我不確定。因?yàn)槲乙呀?jīng)啟用了 Cors,并且在 axios 選項(xiàng)的標(biāo)題中也啟用了,所以我不確定問題是什么..后端:應(yīng)用程序.jsconst express = require("express");const app = express();const cors = require("cors");const bodyParser = require("body-parser");const logger = require("morgan");const session = require("express-session");const FileStore = require("session-file-store")(session);const upload = require("express-fileupload");app.use(upload());console.log("Server Started!");app.use(function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT"); res.header( "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept" ); next();});app.use(logger("dev"));app.use(cors);app.use(bodyParser.urlencoded({ extended: true }));app.use(bodyParser.json());app.use( session({ resave: false, secret: "hello", saveUninitialized: true, is_logged_in: false, }));const indexRouter = require("./routes/index");app.use("/", indexRouter);app.get('/', function (req, res) { res.send('<h1>hello world</h1>')});module.exports = app;我不確定后端還需要什么,所有路由和東西都由 nextjs 處理。
使用帶有 React 的 Axios 發(fā)布到快遞后端時(shí)遇到問題
qq_笑_17
2022-07-21 10:58:26