~ meteor deploy your-app.com --settings production-settings.json
Kadira is a 100 per cent bootstrapped company from my personal funds.
[...]
We were pretty successful with Meteor, but the market of Meteor apps was pretty small for us.
That situation was really no better than, say, PHP's. In many ways, PHP was actually more suited for the "server rendering of HTML" job
~ yarn create next-app my-app
~ cd my-app
~ yarn next
Yarn > 0.25
~ npm install -g create-next-app
~ create-next-app my-app
~ cd my-app
~ npm run dev
NPM
export default () => <h1>What a new Page !</h1>;
import Head from 'next/head';
export default ({ title = 'This is the default title' }) => (
<Head>
<title>{title}</title>
<meta charSet="utf-8" />
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head>
);
export default ({ url: { query: { id } } }) => (
<div>
<h1>Mon identifiant est : {id}</h1>
</div>
);
/sub/path
{
"name": "create-next-example-app",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^2.3.1",
"react": "^15.5.4",
"react-dom": "^15.5.4"
}
}
{
"name": "create-next-example-app",
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"next": "^2.3.1",
"react": "^15.5.4",
"react-dom": "^15.5.4"
}
}
package.json
const { createServer } = require('http');
const { parse } = require('url');
const next = require('next');
const pathMatch = require('path-match');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
const route = pathMatch();
const match = route('/rennesjs/:param');
app.prepare().then(() => {
createServer((req, res) => {
const { pathname, query } = parse(req.url, true);
const params = match(pathname);
if (params === false) {
handle(req, res);
return;
}
app.render(req, res, '/sub/path', Object.assign(params, query));
}).listen(3000, err => {
if (err) throw err;
console.log('> Ready on http://localhost:3000');
});
});
server.js
export default ({ url: { query: { id, param } } }) => (
<div>
<h1>Mon identifiant est : {id} et mon chemin est : {param}</h1>
</div>
);
/pages/sub/path.js
import Link from 'next/link';
export default ({ url: { query: { id, param } } }) => (
<div>
<h1>Mon identifiant est : {id} et mon chemin est : {param}</h1>
<Link href="/rennesjs">
<a title="Retour à Rennes Js">
plip
</a>
</Link>
</div>
);
/pages/sub/path.js
<Link prefetch href="/rennesjs">
<a title="Retour à Rennes Js">
plip
</a>
</Link>
import Router from 'next/router'
...
{
Router.prefetch('/rennesjs')
}
import Link from 'next/link';
import Head from 'next/head';
export default ({ children, title = 'This is the default title' }) => (
<div>
<Head>
<title>{title}</title>
<meta charSet="utf-8" />
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head>
<header>
<nav>
<Link href="/"><a>Home</a></Link> |
<Link href="/rennesjs"><a>Rennes JS</a></Link> |
</nav>
</header>
{children}
<footer>
Je suis en bas mais je suis bien
</footer>
</div>
);
/components/layout.js
import Link from 'next/link';
import Layout from '../../components/layout';
export default ({ url: { query: { id, param } } }) => (
<Layout>
<h1>Mon identifiant est : {id} et mon chemin est : {param}</h1>
<Link href="/rennesjs">
<a title="Retour à Rennes Js">
plip
</a>
</Link>
</Layout>
);
/pages/sub/path.js
import Link from 'next/link';
import Layout from '../../components/layout';
import axios from 'axios';
const path = ({ url: { query: { id, param } }, avatar }) => (
<Layout>
<h1>Mon identifiant est : {id} et mon chemin est : {param}</h1>
<Link href="/rennesjs">
<a title="Retour à Rennes Js">
plip
</a>
</Link>
<br />
<img src={avatar} width="60px" />
</Layout>
);
path.getInitialProps = async ({ req }) => {
const res = await axios.get('https://api.github.com/users/mlecoq/events');
return { avatar: res.data[0].actor.avatar_url };
};
export default path;
/pages/sub/path.js
/pages/sub/path.js
~ yarn add redux
~ yarn add react-redux
~ yarn add next-redux-wrapper
import { createStore } from 'redux';
export const actionTypes = {
ADD: 'ADD',
REMOVE: 'REMOVE',
};
const reducer = (state = { count: 0 }, action) => {
switch (action.type) {
case actionTypes.ADD:
return { ...state, count: state.count + 1 };
case actionTypes.REMOVE:
return { ...state, count: state.count - 1 };
default:
return state;
}
};
export const makeStore = initialState => {
return createStore(reducer, initialState);
};
export function addCount() {
return { type: actionTypes.ADD };
}
export function removeCount() {
return { type: actionTypes.REMOVE };
}
Store
import withRedux from 'next-redux-wrapper';
import Link from 'next/link';
import { bindActionCreators } from 'redux';
import { makeStore, addCount } from '../store/store';
const AddCounter = ({ add, count }) => (
<div>
<h1>Compteur: <span>{count}</span></h1>
<button onClick={add}>Plus !</button>
<br />
<Link href="/remove">Moins</Link>
</div>
);
const mapStateToProps = ({ count }) => ({ count });
const mapDispatchToProps = dispatch => ({
add: bindActionCreators(addCount, dispatch),
});
export default withRedux(makeStore, mapStateToProps, mapDispatchToProps)(
AddCounter,
);
pages/add.js
import withRedux from 'next-redux-wrapper';
import Link from 'next/link';
import { bindActionCreators } from 'redux';
import { makeStore, addCount } from '../store/store';
const AddCounter = ({ add, count }) => (
<div>
<h1>Compteur: <span>{count}</span></h1>
<button onClick={add}>Plus !</button>
<br />
<Link href="/remove">Moins</Link>
</div>
);
AddCounter.getInitialProps = ({ store }) => {
store.dispatch(addCount());
};
const mapStateToProps = ({ count }) => ({ count });
const mapDispatchToProps = dispatch => ({
add: bindActionCreators(addCount, dispatch),
});
export default withRedux(makeStore, mapStateToProps, mapDispatchToProps)(
AddCounter,
);
pages/add.js
Site Statique
import dynamic from 'next/dynamic'
const DynamicComponent1 = dynamic(import('../components/hello1'))
const DynamicComponent2 = dynamic(import('../components/hello2'))
export default () => (
<div>
<Header />
<DynamicComponent />
<p>HOME PAGE is here!</p>
</div>
)
Micro Service
Hyper
Pkg
pkg . --targets node6-macos-x64