POST https://localhost:5000/add-user/ net::ERR_CONNECTION_CLOSED
Uncaught (in promise) TypeError: Failed to fetch
Делаю запрос через свой хук, подскажите пожалуйста в чем может быть проблема?
CLIENT
const useDb = useDatabase();
<button onClick={() => useDb.addUser(userInfo.email, userInfo.name, userInfo.password)}>Submit</button>
HOOK
export default function useDatabase() {
function addUser(email, name, password) {
let newUser = {
email: email,
name: name,
password: password
}
fetch(`https://localhost:5000/add-user/`, {
method: 'POST',
headers: {'Content-type': 'application/json'},
body: JSON.stringify(newUser)
}).then(data => console.log(data));
}
return {addUser}
}
SERVER
const dotenv = require('dotenv');
const dbService = require('./dbService');
const cors = require('cors');
dotenv.config();
const express = require('express');
app = express();
app.use(cors());
app.use(express.json());
const port = process.env.SERVER_PORT;
app.listen(port, () => {console.log('server started on port ' + port)})
app.post('/add-user', function(req, res) {
console.log(req.body)
});