Search code examples
node.jsreactjsreact-fullstack

(Design question) How to decouple front- and back-end to protect routing (backend) code? (Node.js - Express - React)


Context:

I'm making a React website that draws information from the Google Sheets API and formats specific rows into a data visualization. There are columns I don't want to share because of sensitivity of information, and fortunately there are ways to share only specified columns, but that isn't why I'm asking the following:

Problem:

I want to have a Node API that handles requests from a React front-end, but whose code isn't available on the client's browser (for example, in the bundle.js file created during build).

Clarification: I have noticed that when running most Node-React application examples locally and when building them with webpack, you end up with one bundle.js file that contains Node request-handling code being delivered to the browser on page load.

Proposal:

Do I need to deploy two separate apps (one for Node, the other for React), or can I keep them together without the server code being visible to the client?

EDIT POST ANSWER:

you end up with one bundle.js file that contains Node request-handling code being delivered to the browser on page load.

This was untrue. The code I had assumed to be request-handling code was client side request-calling code.


Solution

  • It is already decoupled. There is nothing you need to do.

    Note that the security of your node.js server code depends on your server configuration, not node.js. If you access your server via unencrypted file sharing or FTP then your node server code is still not safe.

    Even when using encryption, avoid compromised protocols such as SSL or TLSv1.0 (use TLSv1.3 instead for things like FTPS)