egg-frost
v0.1.0
Published
Egg Framework Plugin for integrating NextJS server into Egg
Downloads
1
Maintainers
Readme
Status: still in development. Please do not use in production environment
egg-frost
Inspired by tokenfoundry koa-react-ssr.
Install
$ npm i egg-frost --save
Usage
// {app_root}/config/plugin.js
exports.frost = {
enable: true,
package: 'egg-frost',
};
Configuration
// {app_root}/config/config.default.js
exports.frost = {
client: {
/* This is used to start next.js server in dev mode or production mode. [Default: dev mode] */
env: ''
},
};
see config/config.default.js for more detail.
Pages
Folder Structure
- [root-dir]
- pages
- Home.js
- ...
- ...
- ...
Sample page
// Home.js
import React from 'react';
import Head from 'next/head';
export function withSSR() {
return function adapter(ScreenComponent) {
// eslint-disable-next-line no-param-reassign
ScreenComponent.getInitialProps = function getInitialProps({ query }) {
return query;
};
return ScreenComponent;
};
}
class HomeScreen extends React.PureComponent {
render() {
return (
<div>
<Head>
<title>My Page</title>
</Head>
<h1>Hi pg!</h1>
</div>
)
}
}
export default withSSR()(HomeScreen);
TODO
- Write Tests
- Update Documentation
Questions & Suggestions
Please open an issue here.