node.jsreactjsexpressssl

net::ERR_SSL_PROTOCOL_ERROR on http POST to express server


I'm trying to post from a react client to an express server on localhost and I get this error in google chrome.

react app: http://localhost:3000 express app: http://localhost:5000

POST https://localhost:5000/upload net::ERR_SSL_PROTOCOL_ERROR

I don't have any SSL https self signed certificate, but do I need to? I have used create-react-app inside a directory within my express application to bootstrap my front-end so I'm unaware if maybe a webpack setting somewhere is trying to handle http as https for this particular operation?

I haven't used any bootstrapping for my express js application and I'll include my server file below for reference.

const express = require ('express')
const bodyParser = require ('body-parser')
const port = 5000

var app = express()
var cors = require("cors");

app.use(cors())
app.use(bodyParser())
app.listen(port, () => console.log(`Example app listening on port ${port}!`))



app.post('/upload', (req,res)=>{
    if (req.files === null ){
        return res.status(400).json({message: 'no image uploaded please try again'})
    }else{
        const file = req.files.file
        let body = req.body
        res.json({body})
    } 
})

I know there are a fair few questions on this issue but they weren't relevant or didn't provide me any insight. I have tried making sure the ports are allowed through my firewall aswell. I have also cleared my browser cache.


Solution

  • This has been discussed in multiple posts

    By default you cannot call localhost request on browsers but you can disable the security

    Check here : Disable same origin policy in Chrome