pedrobullo / boilerplate-nutella Goto Github PK
View Code? Open in Web Editor NEWReact Redux Server-Side-Rendering with Razzle, Code-Splitting, SCSS and CSS Modules
License: MIT License
React Redux Server-Side-Rendering with Razzle, Code-Splitting, SCSS and CSS Modules
License: MIT License
It may be a good idea to set cache on the static files.
app.use(Express.static(process.env.RAZZLE_PUBLIC_DIR, { maxAge: 0 }));
app.use((_, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization');
res.header('Cache-Control', 'no-cache, private');
next();
});
Based on that issue jaredpalmer/razzle#356 I found a way to change the port
by using the process.env
.
const getEnv = c => process.env[c];
const PORT = getEnv('PORT');
export default Loadable.preloadAll()
.then(() => express()
.use((req, res) => server.handle(req, res))
.listen(PORT, (err) => {
if (err) {
console.error(err);
return;
}
console.log(`🤰 Running at: http://localhost:${PORT}/.`);
})
);
A good option is https://github.com/expressjs/compression
// Apply body Parser and server public assets and routes
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use((_, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization');
res.header('Cache-Control', 'no-cache, private');
next();
});
app.use(compression()); // <--------------------------------------------------------------
app.use(Express.static(process.env.RAZZLE_PUBLIC_DIR));
app.use(appRouting);
parseQueryString
function on DataLoader
needs to be wrapped with try-catch
expression.
The server is not handling the missing files and are triggering the components need
functions based on the current route.
When Dataloader component tries to fechData it passes a location.pathname
which contains only the path giving away of querystring params.
componentDidUpdate(prevProps) {
const navigated = this.props.location !== prevProps.location;
if (navigated) {
const { store } = this.context; // eslint-disable-line
fetchData(store, this.props.location.pathname); // eslint-disable-line
}
}
One way to solve that is by including the querystring params into url string.
componentDidUpdate(prevProps) {
const navigated = this.props.location !== prevProps.location;
if (navigated) {
const { store } = this.context; // eslint-disable-line
fetchData(store, this.props.location.pathname + `/` + this.props.location.search); // eslint-disable-line
}
}
This is just a quick solution, the better way may be passing the entire location obj to fetchData to handle that.
Build folder is getting extremely larger because of the hot reload feature.
Implement a non-www redirect feature on the server and give an option to choose between with www
or not.
Here an example:
...
function wwwRedirect(req, res, next) {
if (req.headers.host.slice(0, 4) === 'www.') {
var newHost = req.headers.host.slice(4);
return res.redirect(301, req.protocol + '://' + newHost + req.originalUrl);
}
next();
};
app.use(wwwRedirect);
At this moment, the callApi
function is handling just url params and not querystring params.
For some reason I'm getting logs on client from need
functions. It can be related with nested routes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.