在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:CircleCI-Public/circleci-demo-javascript-express开源软件地址:https://github.com/CircleCI-Public/circleci-demo-javascript-express开源编程语言:JavaScript 91.0%开源软件介绍:CircleCI Demo JavaScript/Express.jsThis project was built from a MERN Starter kit (original URLs broken). Discussions still active here. MERN is Mongo, Express, React and NodeJS. See the JavaScript language guide for CircleCI here. Quickstart
Note : Please make sure your MongoDB is running. For MongoDB installation guide see this. Also Available Commands
File StructureWebpack ConfigsMERN uses Webpack for bundling modules. There are four types of Webpack configs provided The Webpack configuration is minimal and beginner-friendly. You can customise and add more features to it for production build. ServerMERN uses express web framework. Our app sits in server.js where we check for NODE_ENV. If NODE_ENV is development, we apply Webpack middlewares for bundling and Hot Module Replacement. Server Side RenderingWe use React Router's match function for handling all page requests so that browser history works. All the routes are defined in // Server Side Rendering based on routes matched by React-router.
app.use((req, res) => {
match({
routes,
location: req.url
}, (err, redirectLocation, renderProps) => {
if (err) {
return res.status(500).end('Internal server error');
}
if (!renderProps) {
return res.status(404).end('Not found!');
}
const initialState = {
posts: [],
post: {}
};
const store = configureStore(initialState);
fetchComponentData(store.dispatch, renderProps.components, renderProps.params).then(() => {
const initialView = renderToString(
<Provider store = {store} >
<RouterContext {...renderProps}/>
</Provider>
);
const finalState = store.getState();
res.status(200).end(renderFullPage(initialView, finalState));
}).catch(() => {
res.end(renderFullPage('Error', {}));
});
});
});
If there's an error in matching we return 500 status code, if no matches are found we return 404 status code. If a match is found then, we need to create a new Redux Store instance. Note: A new Redux Store has populated afresh on every request.
ClientClient directory contains all the shared components, routes, modules. componentsThis folder contains all the common components which are used throughout the project. index.jsIndex.js simply does client side rendering using the data provided from modulesModules are the way of organising different domain-specific modules in the project. A typical module contains the following
MiscImporting AssetsAssets can be kept where you want and can be imported into your js files or css files. Those fill be served by webpack in development mode and copied to the dist folder during production. ES6 supportWe use babel to transpile code in both server and client with DockerThere are docker configurations for both development and production. To run docker for development,
To run docker for production,
Make your MERNIn this version, we enabled the
Modifying Generatorsmern.jsonIt contains a blueprints array. Each object in it is the config for a generator. A blueprint config contains the name, description, usage, and files array. An example blueprint config
A file object contains
Also,
Blueprint filesBlueprints are basically ejs templates which are rendered with the same three variables( CaveatsFOUC (Flash of Unstyled Content)To make the hot reloading of CSS work, we are not extracting CSS in development. Ideally, during server rendering, we will be extracting CSS, and we will get a .css file, and we can use it in the html template. That's what we are doing in production. In development, after all scripts get loaded, react loads the CSS as BLOBs. That's why there is a second of FOUC in development. Client and Server Markup MismatchThis warning is visible only on development and totally harmless. This occurs to hash difference in LicenseMERN is released under the MIT License. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论