3

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.

monsterpiece
  • 579
  • 4
  • 16
  • 1
    _"I don't have any SSL https self signed certificate, but do I need to?"_ **Short Answer:** yes. **Long Answer:** You'll need a self-signed certificate for your localhost environment and will need to add it to your `Windows` certificate store (if you're using _Microsoft Windows_). Without the certificate added in your certificate store, you will still receive an error message that the certificate was signed by a _Certificate Authority_ that could not be verified. Once you deploy to a production environment, you'll want to use a certificate from a valid CA (free through _Let's Encrypt_ or paid) – War10ck Mar 05 '20 at 15:28

2 Answers2

0

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

Charles dB
  • 339
  • 1
  • 9
0

I had the same issue and changed the URL to http://localhost:5000/upload instead of using https://localhost:5000/upload.

Showrin Barua
  • 1,437
  • 4
  • 19