Search code examples
node.jsstripe-paymentscpanelvps

how to deploy a react build app with a nodejs backend that servers a stripe checkout


Hi i knew this is about to ask direct and concise questions but this is my first professional app and i really don't know how to deploy it

i have a react build page to the client side and i have my nodejs back-end separated where basically the client side page fetch the backend's localhost port and POST the cart object items so the back-end send a JSON.stringify({ url: session.url }) where the client could pay his purchases

so far I have only bought the domain.

so basically...

1- i don't know how to pass from localhost to my domain.

2- i don't know if the VPS it's all that i need or i need something else.

3- i don't know if i need two hosts, One for start my nodejs backend and receive all the POST's from my website, And another to host my website page.

4-it's the VPS the right option or could i buy a shared hosting that support nodejs and use cpanel to upload my files and start the back-end?

i tried to submit my react client page on git hub pages to test and learn more about it, I change the fetch from the "localhost//3000" to http://myIpdirection:PORT/checkout where basically my backend starts but i receive an error from the local browser where it says:

"The page at "https://mywebsite.io" was loaded over HTTPS, but requested an insecure resource "http://myIpdirection:PORT/checkout" This request has been blocked; the content must be served over HTTPS.

this is very important to me cause this app is to help a relative of mine

what should i do?


Solution

  • It is quite tricky to give advice without too much information, but there are some norms we can go over.

    You are using a create-react-app frontend, meaning everything here is purely done in the users browser, nothing is done on your server.

    So you mention you see an error in your browser when you request your backend. This is because your backend uses HTTP, meaning all traffic is sent in plain text! For anything backend related, you're going to want to encrypt it! For example, if your request included payment details, they will be shown in plain text and someone could see that request!! Not good!

    If you're using an express backend its pretty simple to get HTTPS working, with a self-signed certificate locally. This still isn't a great solution as it isnt a trusted certificate but can help you debug. This resource should help you setup a self signed certificate so you can use https.

    To get a trusted cert you may want to look at using Lets Encrypt, this system allows you to get a trusted certificate for free.

    Once you have HTTPS setup you will be able to make requests to your server without errors in your console.

    With regards to needing just one VPS, that is an architectural question and there is no right answer, but there are certainly bad answers. It's hard to give advice on system architecture without more details.

    Hope this somewhat helps.