I am trying to use the login API I made using node, however, whenever I call the API using Axios, it gives me a request failed in the console.
This is how I use axios to call my method:
axios
.post(
"http://localhost:8080/staffMember/login",
{
email: "[email protected]",
password: "Flintstone",
},
{
headers: {
"Content-Type": "application/json",
},
}
)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error.message);
});
};
And this is my login page and console :
This is my backend configuration:
require("dotenv").config();
const mongoose = require("mongoose");
const express = require("express");
const app = express();
const staffMember = require("./routers/staffMember.router.js");
const hrMember = require("./routers/hrMember.router.js");
const academicMember = require("./routers/academic members/academicMember.router");
const headOfDepartment = require("./routers/academic members/headOfDepartment.router");
const courseInstructor = require("./routers/academic members/courseInstructor.router");
const courseCoordinator = require("./routers/academic members/courseCoordinator.router");
var cors = require("cors");
app.use(cors());
mongoose
.connect(process.env.DATABASE_CONN_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
})
.then(() => {
console.log("DB connected");
})
.catch(() => {
console.log("DB connection failed");
});
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use("/staffMember", staffMember);
app.use("/hrMember", hrMember);
app.use("/academicMember", academicMember);
app.use("/courseInstructor", courseInstructor);
app.use("/courseCoordinator", courseCoordinator);
app.use("/headOfDepartment", headOfDepartment);
module.exports = app;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…