// Next app
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
// Start Next app
app.prepare()
.then(() => {
// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set('locals', {
_: require('lodash'),
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').config();
// Next app
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const keystone = require('keystone');
// Setup Route Bindings
exports = module.exports = nextApp => keystoneApp => {
// Next request handler
const handle = nextApp.getRequestHandler();
keystoneApp.get('/api/posts', (req, res, next) => {
import { Component } from 'react';
class App extends Component {
render() {
return (
<div>Hello World</div>
);
};
}
import Document, { Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'
export default class MyDocument extends Document {
static getInitialProps({ renderPage }) {
const { html, head, errorHtml, chunks } = renderPage()
const styles = flush()
return { html, head, errorHtml, chunks, styles }
}
import { Component } from 'react';
import axios from 'axios'
class App extends Component {
static async getInitialProps() {
let response = await axios.get('http://localhost:3000/api/posts');
return { posts: response.data };
}
static async getInitialProps({ isServer, store }) {
store.dispatch({ type: type.MY_ACTION });
console.log(store.getState());
return {};
}
import {
createStore,
applyMiddleware,
combineReducers,
compose,
} from 'redux';
import createSagaMiddleware, { END } from 'redux-saga';
import reducers from './reducers';
static async getInitialProps({ isServer, store }) {
// Fetch today NASA APOD
await store.execSagaTasks(isServer, dispatch => {
dispatch(fetchApodStart());
});
console.log('');
console.log('###############################');
console.log('### Fetched today NASA APOD ###');
OlderNewer