I am trying to achieve server side rendering with my create-react-app project. I really don't need routes because it is a one-page application. I look through some articles, but they seem to me rather complicated. Can someone let me know how to do this, or link me to simpler articles?
Here is the code so far: -
The main component of the application that imports other components: -
import React, { Component } from "react";
import HomePage from "./HomePage";
import "./App.css";
class App extends Component {
render() {
return(
<div>
<HomePage/>
</div>
);
}
}
export default App;
Express code so far: -
import express from "express";
import React from "react";
import { renderToString } from "react-dom/server";
import App from "../src/App";
const app = express();
app.use(express.static("../public"));
app.get('*', (req, res) => {
res.send(`
<!DOCTYPE html>
<head>
<title>Universal React</title>
</head>
<body>
<div id="root">${renderToString(<App/>)}</div>
</body>
</html>
`);
});
app.listen(3000, () => {
console.log('Server running on PORT 3000');
})
All the articles or videos that I have checked so far use webpack and make changes to the webpack.config.js file, but I use the Create-react-app application that comes with the web package turned on, there is no configuration file, so I'm a little confused about how to make the necessary changes?