Reputation: 891
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
Upvotes: 1
Views: 2013
Reputation: 11755
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);
Upvotes: 1