1

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

Philip Nguyen
  • 871
  • 2
  • 10
  • 29
  • Make an api call to node and hide on its response basis – Black Mamba Aug 08 '18 at 13:58
  • 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 Aug 08 '18 at 13:58
  • 1
    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 Aug 08 '18 at 14:00
  • It will make my product harder to reverse engineer from a gui aspect – Philip Nguyen Aug 08 '18 at 14:17
  • *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 Aug 08 '18 at 17:22

1 Answers1

1

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);
SoluableNonagon
  • 11,541
  • 11
  • 53
  • 98