我關注 CRUD 應用程式的JavaScript Mastery視頻。我在連接前端和后端時遇到問題。當我嘗試提交表單時,我提交了console log。它顯示了
POST http://localhost:5000/posts net::ERR_CONNECTION_RESET
我檢查了服務器和資料庫連接,沒有任何問題。
錯誤截圖

index.js
import axios from 'axios';
const url = 'http://localhost:5000/posts';
export const fetchPosts = () => axios.get(url)
export const createPost = (newPost) => axios.post(url, newPost);
服務器/index.js
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";
import postRoutes from './routes/posts.js';
const app = express();
app.use(bodyParser.json({limit: "30mb", extended: true}));
app.use(bodyParser.urlencoded({limit: "30mb", extended: true}));
app.use(cors());
app.use('/posts', postRoutes)
const CONNECTION_URL = "mongodb srv://mominriyadh:@######@cluster0.jqiet.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const PORT = process.env.PORT || 5000;
mongoose.connect(CONNECTION_URL, {useNewUrlParser: true, useUnifiedTopology: true})
.then(() => app.listen(PORT, () => console.log(`server running on port: ${PORT}`)))
.catch((error) => console.log(error.message));
mongoose.set('useFindAndModify', false);
uj5u.com熱心網友回復:
該錯誤來自您的擴展之一,而不是來自您的代碼。什么是具體的。self.processResponse 不是函式 #33355
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/465634.html
上一篇:顯示地圖函式內另一個陣列的資料
