1
votes

I want to hide my react source code if possible from my users.

I might be completely wrong about this, but I think I remember reading something about how node js can render components server side, then send those rendered components to the front end.

Is it possible to hide my react component source code by using this method? Or is there any way for node js to hide my react source code?

If there is any other method of hiding react source code, I would appreciate any advice.

Thanks

1
Make an api call to node and hide on its response basisBlack Mamba
I believe you are referring to React's Server-side Rendering. I believe you're better off just googling about it to get going.Chris
Why are you concerned about trying to hide your react code in the first place? Chances are that if there's content you need to hide it shouldn't be anywhere near your front end in the first place.Adam
It will make my product harder to reverse engineer from a gui aspectPhilip Nguyen
Is it possible to hide my react component source code by using this method? - there's nothing to hide, this is server side code which isn't exposed to client side. It's unclear what's your case and whether it's possible to render whole app to static html without loss of functionality.Estus Flask

1 Answers

1
votes

https://reactjs.org/docs/react-dom-server.html

So React DOM Server can render static markup. It will literally render just HTML, so don't expect any click events or anything.

So your server can start like this:

import express from 'express';
import React from 'react';
import { renderToString } from 'react-dom/server';
import RootOfYourApp from './src/RootOfYourApp';

const port = 3000;
const server = express();

server.get('/somePath', (req, res) => {
  const body = renderToString(<RootOfYourApp />);

  res.send(body);
});

server.listen(port);