I am creating a DHL API for checking shipment rates. I have uploaded my Node.js Server using putty and it is running correctly when I enter my IP address and port number.
In development, there are no erros or issues and I get back the response and get the rates back from the form I have set up for my users.
but in Production, when I upload my website to Hostinger I get this error " Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR"
In production, it sends my post request with HTTPS instead of HTTP. And even when I change the HTTPS to HTTP in the browser I get another error saying "Cannot GET /api/dhl"
Here are some images to help make it more clear:
The Errors.
When my website submits the post request with HTTPS instead of HTTP.
When I manually change the URL from HTTPS to HTTP
What am I doing wrong? Why is this happening and how can I fix it?
Here is my code:
const express = require('express');
const port = 3001
app.post('/api/dhl', (req, res) => {
const accountNum = req.body.accountNum
const fromCountriesCode = req.body.fromCountriesCode
const fromCountriesCapital = req.body.fromCountriesCapital
const fromCity = req.body.fromCity
const fromPostalCode = req.body.fromPostalCode
const toCountriesCode = req.body.toCountriesCode
const toCountriesCapital = req.body.toCountriesCapital
const toCity = req.body.toCity
const toPostalCode = req.body.toPostalCode
const weight = parseInt(req.body.weight)
const plannedShippingDate = req.body.date
const len = "5"
const width = "5"
const height = "5"
const isCustomsDeclarable = 'false' 
const unitOfMeasurement = 'metric'
console.log(weight)
console.log(fromCountriesCode)
console.log(toCountriesCode)
console.log(fromCity)
console.log(toCity)
var options = { method: 'POST',
url: 'https://express.api.dhl.com/mydhlapi/rates',
headers: 
 { 'postman-token': '',
   'cache-control': 'no-cache',
   authorization: 'Basic myauthkey',
   'content-type': 'application/json' },
body: 
 { customerDetails: 
    { shipperDetails: 
       { postalCode: fromPostalCode,
         cityName: fromCity,
         countryCode: fromCountriesCode,
         addressLine1: '0' },
      receiverDetails: 
       { postalCode: toPostalCode,
         cityName: toCity,
         addressLine1: '0',
         countryCode: toCountriesCode }
         },
   accounts: [ { typeCode: 'shipper', number: 'my account number' } ],
   plannedShippingDateAndTime: '2021-08-25T13:00:00GMT+00:00',//Might need to change later
   unitOfMeasurement: 'metric',
   isCustomsDeclarable: true,
   monetaryAmount: [ { typeCode: 'declaredValue', value: 10, currency: 'BHD' } ],
   requestAllValueAddedServices: false,
   returnStandardProductsOnly: false,
   nextBusinessDay: false,
   packages: [ { weight: weight, dimensions: { length: 5, width: 5, height: 5 } } ] },
json: true };
request(options, function (error, response, body) {
    if (error) throw new Error(error);
    res.send(body)
    console.log(body);
  });
});
//Start the Server
app.listen(port, () => {
  console.log(`Server running at :${port}/`);
});
My Check-Rates File: const getRateEstimate = () => {
axios.post('http://MY_IP:3001/api/dhl', {
    fromCity,
    fromCountriesCapital,
    fromCountriesCode,
    fromPostalCode,
    toCountriesCapital,
    toCountriesCode,
    toPostalCode,
    toCity,
    weight,
 }).then(response => {
        console.log(response)
        setData(response.data);
 }).catch(e => {
     console.log(e)
 });
}



