Unverified Commit 9c4eefcd authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add prettier for examples directory (#5909)

* Add prettier for examples directory

* Fix files

* Fix linting

* Add prettier script in case it has to be ran again
parent 6e2cbfaf
...@@ -7,7 +7,9 @@ const ActiveLink = ({ router, children, ...props }) => { ...@@ -7,7 +7,9 @@ const ActiveLink = ({ router, children, ...props }) => {
let className = child.props.className || null let className = child.props.className || null
if (router.pathname === props.href && props.activeClassName) { if (router.pathname === props.href && props.activeClassName) {
className = `${className !== null ? className : ''} ${props.activeClassName}`.trim() className = `${className !== null ? className : ''} ${
props.activeClassName
}`.trim()
} }
delete props.activeClassName delete props.activeClassName
......
export default () => ( export default () => <div>About us</div>
<div>About us</div>
)
export default () => ( export default () => <div>This is the contact page.</div>
<div>
This is the contact page.
</div>
)
...@@ -21,7 +21,9 @@ export default class Index extends React.Component { ...@@ -21,7 +21,9 @@ export default class Index extends React.Component {
<h1>Home Page</h1> <h1>Home Page</h1>
<p>Welcome, {name}</p> <p>Welcome, {name}</p>
<div> <div>
<Link href='/about'><a>About Page</a></Link> <Link href='/about'>
<a>About Page</a>
</Link>
</div> </div>
</div> </div>
) )
......
export default () => ( export default () => <div>About us</div>
<div>About us</div>
)
export default () => ( export default () => <div>About 2</div>
<div>About 2</div>
)
export default () => ( export default () => <div>Hello Day</div>
<div>Hello Day</div>
)
import Link from 'next/link' import Link from 'next/link'
export default () => ( export default () => (
<div>Hello World. <Link href='/about'><a>About</a></Link></div> <div>
Hello World.{' '}
<Link href='/about'>
<a>About</a>
</Link>
</div>
) )
...@@ -7,15 +7,13 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -7,15 +7,13 @@ const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const parsedUrl = parse(req.url, true) const parsedUrl = parse(req.url, true)
res.setHeader('Content-Type', 'text/html; charset=iso-8859-2') res.setHeader('Content-Type', 'text/html; charset=iso-8859-2')
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
'use strict' 'use strict'
const {Action, api} = require('actionhero') const { Action, api } = require('actionhero')
module.exports = class CreateChatRoom extends Action { module.exports = class CreateChatRoom extends Action {
constructor () { constructor () {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
const path = require('path') const path = require('path')
exports['default'] = { exports['default'] = {
general: (api) => { general: api => {
const packageJSON = require(api.projectRoot + path.sep + 'package.json') const packageJSON = require(api.projectRoot + path.sep + 'package.json')
return { return {
...@@ -46,16 +46,16 @@ exports['default'] = { ...@@ -46,16 +46,16 @@ exports['default'] = {
cliIncludeInternal: true, cliIncludeInternal: true,
// configuration for your actionhero project structure // configuration for your actionhero project structure
paths: { paths: {
'action': [path.join(__dirname, '/../actions')], action: [path.join(__dirname, '/../actions')],
'task': [path.join(__dirname, '/../tasks')], task: [path.join(__dirname, '/../tasks')],
'public': [path.join(__dirname, '/../static')], public: [path.join(__dirname, '/../static')],
'pid': [path.join(__dirname, '/../pids')], pid: [path.join(__dirname, '/../pids')],
'log': [path.join(__dirname, '/../log')], log: [path.join(__dirname, '/../log')],
'server': [path.join(__dirname, '/../servers')], server: [path.join(__dirname, '/../servers')],
'cli': [path.join(__dirname, '/../bin')], cli: [path.join(__dirname, '/../bin')],
'initializer': [path.join(__dirname, '/../initializers')], initializer: [path.join(__dirname, '/../initializers')],
'plugin': [path.join(__dirname, '/../node_modules')], plugin: [path.join(__dirname, '/../node_modules')],
'locale': [path.join(__dirname, '/../locales')] locale: [path.join(__dirname, '/../locales')]
}, },
// hash containing chat rooms you wish to be created at server boot // hash containing chat rooms you wish to be created at server boot
startingChatRooms: { startingChatRooms: {
...@@ -67,17 +67,17 @@ exports['default'] = { ...@@ -67,17 +67,17 @@ exports['default'] = {
} }
exports.test = { exports.test = {
general: (api) => { general: api => {
return { return {
id: 'test-server-' + process.pid, id: 'test-server-' + process.pid,
serverToken: 'serverToken-' + process.pid, serverToken: 'serverToken-' + process.pid,
developmentMode: true, developmentMode: true,
startingChatRooms: { startingChatRooms: {
'defaultRoom': {}, defaultRoom: {},
'otherRoom': {} otherRoom: {}
}, },
paths: { paths: {
'locale': [ locale: [
// require('os').tmpdir() + require('path').sep + 'locales', // require('os').tmpdir() + require('path').sep + 'locales',
path.join(__dirname, '/../locales') path.join(__dirname, '/../locales')
] ]
...@@ -88,7 +88,7 @@ exports.test = { ...@@ -88,7 +88,7 @@ exports.test = {
} }
exports.production = { exports.production = {
general: (api) => { general: api => {
return { return {
fileRequestLogLevel: 'debug', fileRequestLogLevel: 'debug',
developmentMode: false developmentMode: false
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// error messages can be strings of objects // error messages can be strings of objects
exports['default'] = { exports['default'] = {
errors: (api) => { errors: api => {
return { return {
'_toExpand': false, _toExpand: false,
// /////////////// // ///////////////
// SERIALIZERS // // SERIALIZERS //
...@@ -12,28 +12,28 @@ exports['default'] = { ...@@ -12,28 +12,28 @@ exports['default'] = {
serializers: { serializers: {
servers: { servers: {
web: (error) => { web: error => {
if (error.message) { if (error.message) {
return String(error.message) return String(error.message)
} else { } else {
return error return error
} }
}, },
websocket: (error) => { websocket: error => {
if (error.message) { if (error.message) {
return String(error.message) return String(error.message)
} else { } else {
return error return error
} }
}, },
socket: (error) => { socket: error => {
if (error.message) { if (error.message) {
return String(error.message) return String(error.message)
} else { } else {
return error return error
} }
}, },
specHelper: (error) => { specHelper: error => {
if (error.message) { if (error.message) {
return 'Error: ' + String(error.message) return 'Error: ' + String(error.message)
} else { } else {
...@@ -49,38 +49,51 @@ exports['default'] = { ...@@ -49,38 +49,51 @@ exports['default'] = {
// When a params for an action is invalid // When a params for an action is invalid
invalidParams: (data, validationErrors) => { invalidParams: (data, validationErrors) => {
if (validationErrors.length >= 0) { return validationErrors[0] } if (validationErrors.length >= 0) {
return validationErrors[0]
}
return data.connection.localize('actionhero.errors.invalidParams') return data.connection.localize('actionhero.errors.invalidParams')
}, },
// When a required param for an action is not provided // When a required param for an action is not provided
missingParams: (data, missingParams) => { missingParams: (data, missingParams) => {
return data.connection.localize(['actionhero.errors.missingParams', {param: missingParams[0]}]) return data.connection.localize([
'actionhero.errors.missingParams',
{ param: missingParams[0] }
])
}, },
// user requested an unknown action // user requested an unknown action
unknownAction: (data) => { unknownAction: data => {
return data.connection.localize('actionhero.errors.unknownAction') return data.connection.localize('actionhero.errors.unknownAction')
}, },
// action not useable by this client/server type // action not useable by this client/server type
unsupportedServerType: (data) => { unsupportedServerType: data => {
return data.connection.localize(['actionhero.errors.unsupportedServerType', {type: data.connection.type}]) return data.connection.localize([
'actionhero.errors.unsupportedServerType',
{ type: data.connection.type }
])
}, },
// action failed because server is mid-shutdown // action failed because server is mid-shutdown
serverShuttingDown: (data) => { serverShuttingDown: data => {
return data.connection.localize('actionhero.errors.serverShuttingDown') return data.connection.localize('actionhero.errors.serverShuttingDown')
}, },
// action failed because this client already has too many pending acitons // action failed because this client already has too many pending acitons
// limit defined in api.config.general.simultaneousActions // limit defined in api.config.general.simultaneousActions
tooManyPendingActions: (data) => { tooManyPendingActions: data => {
return data.connection.localize('actionhero.errors.tooManyPendingActions') return data.connection.localize(
'actionhero.errors.tooManyPendingActions'
)
}, },
dataLengthTooLarge: (maxLength, receivedLength) => { dataLengthTooLarge: (maxLength, receivedLength) => {
return api.i18n.localize(['actionhero.errors.dataLengthTooLarge', {maxLength: maxLength, receivedLength: receivedLength}]) return api.i18n.localize([
'actionhero.errors.dataLengthTooLarge',
{ maxLength: maxLength, receivedLength: receivedLength }
])
}, },
// /////////////// // ///////////////
...@@ -89,18 +102,21 @@ exports['default'] = { ...@@ -89,18 +102,21 @@ exports['default'] = {
// The body message to accompany 404 (file not found) errors regarding flat files // The body message to accompany 404 (file not found) errors regarding flat files
// You may want to load in the contnet of 404.html or similar // You may want to load in the contnet of 404.html or similar
fileNotFound: (connection) => { fileNotFound: connection => {
return connection.localize(['actionhero.errors.fileNotFound']) return connection.localize(['actionhero.errors.fileNotFound'])
}, },
// user didn't request a file // user didn't request a file
fileNotProvided: (connection) => { fileNotProvided: connection => {
return connection.localize('actionhero.errors.fileNotProvided') return connection.localize('actionhero.errors.fileNotProvided')
}, },
// something went wrong trying to read the file // something went wrong trying to read the file
fileReadError: (connection, error) => { fileReadError: (connection, error) => {
return connection.localize(['actionhero.errors.fileReadError', {error: String(error)}]) return connection.localize([
'actionhero.errors.fileReadError',
{ error: String(error) }
])
}, },
// /////////////// // ///////////////
...@@ -108,41 +124,54 @@ exports['default'] = { ...@@ -108,41 +124,54 @@ exports['default'] = {
// /////////////// // ///////////////
verbNotFound: (connection, verb) => { verbNotFound: (connection, verb) => {
return connection.localize(['actionhero.errors.verbNotFound', {verb: verb}]) return connection.localize([
'actionhero.errors.verbNotFound',
{ verb: verb }
])
}, },
verbNotAllowed: (connection, verb) => { verbNotAllowed: (connection, verb) => {
return connection.localize(['actionhero.errors.verbNotAllowed', {verb: verb}]) return connection.localize([
'actionhero.errors.verbNotAllowed',
{ verb: verb }
])
}, },
connectionRoomAndMessage: (connection) => { connectionRoomAndMessage: connection => {
return connection.localize('actionhero.errors.connectionRoomAndMessage') return connection.localize('actionhero.errors.connectionRoomAndMessage')
}, },
connectionNotInRoom: (connection, room) => { connectionNotInRoom: (connection, room) => {
return connection.localize(['actionhero.errors.connectionNotInRoom', {room: room}]) return connection.localize([
'actionhero.errors.connectionNotInRoom',
{ room: room }
])
}, },
connectionAlreadyInRoom: (connection, room) => { connectionAlreadyInRoom: (connection, room) => {
return connection.localize(['actionhero.errors.connectionAlreadyInRoom', {room: room}]) return connection.localize([
'actionhero.errors.connectionAlreadyInRoom',
{ room: room }
])
}, },
connectionRoomHasBeenDeleted: (room) => { connectionRoomHasBeenDeleted: room => {
return api.i18n.localize('actionhero.errors.connectionRoomHasBeenDeleted') return api.i18n.localize(
'actionhero.errors.connectionRoomHasBeenDeleted'
)
}, },
connectionRoomNotExist: (room) => { connectionRoomNotExist: room => {
return api.i18n.localize('actionhero.errors.connectionRoomNotExist') return api.i18n.localize('actionhero.errors.connectionRoomNotExist')
}, },
connectionRoomExists: (room) => { connectionRoomExists: room => {
return api.i18n.localize('actionhero.errors.connectionRoomExists') return api.i18n.localize('actionhero.errors.connectionRoomExists')
}, },
connectionRoomRequired: (room) => { connectionRoomRequired: room => {
return api.i18n.localize('actionhero.errors.connectionRoomRequired') return api.i18n.localize('actionhero.errors.connectionRoomRequired')
} }
} }
} }
} }
exports['default'] = { exports['default'] = {
i18n: (api) => { i18n: api => {
return { return {
// visit https://github.com/mashpie/i18n-node to see all configuration options // visit https://github.com/mashpie/i18n-node to see all configuration options
// locale path can be configired from within ./config/api.js // locale path can be configired from within ./config/api.js
...@@ -28,7 +28,7 @@ exports['default'] = { ...@@ -28,7 +28,7 @@ exports['default'] = {
} }
exports.test = { exports.test = {
i18n: (api) => { i18n: api => {
return { return {
updateFiles: true updateFiles: true
} }
......
...@@ -4,16 +4,18 @@ const fs = require('fs') ...@@ -4,16 +4,18 @@ const fs = require('fs')
const cluster = require('cluster') const cluster = require('cluster')
exports['default'] = { exports['default'] = {
logger: (api) => { logger: api => {
let logger = {transports: []} let logger = { transports: [] }
// console logger // console logger
if (cluster.isMaster) { if (cluster.isMaster) {
logger.transports.push(function (api, winston) { logger.transports.push(function (api, winston) {
return new (winston.transports.Console)({ return new winston.transports.Console({
colorize: true, colorize: true,
level: 'info', level: 'info',
timestamp: function () { return api.id + ' @ ' + new Date().toISOString() } timestamp: function () {
return api.id + ' @ ' + new Date().toISOString()
}
}) })
}) })
} }
...@@ -26,15 +28,18 @@ exports['default'] = { ...@@ -26,15 +28,18 @@ exports['default'] = {
fs.mkdirSync(logDirectory) fs.mkdirSync(logDirectory)
} catch (e) { } catch (e) {
if (e.code !== 'EEXIST') { if (e.code !== 'EEXIST') {
throw (new Error('Cannot create log directory @ ' + logDirectory)) throw new Error('Cannot create log directory @ ' + logDirectory)
} }
} }
} }
return new (winston.transports.File)({ return new winston.transports.File({
filename: api.config.general.paths.log[0] + '/' + api.pids.title + '.log', filename:
api.config.general.paths.log[0] + '/' + api.pids.title + '.log',
level: 'info', level: 'info',
timestamp: function () { return api.id + ' @ ' + new Date().toISOString() } timestamp: function () {
return api.id + ' @ ' + new Date().toISOString()
}
}) })
}) })
...@@ -52,7 +57,7 @@ exports['default'] = { ...@@ -52,7 +57,7 @@ exports['default'] = {
} }
exports.test = { exports.test = {
logger: (api) => { logger: api => {
return { return {
transports: null transports: null
} }
......
exports['default'] = { exports['default'] = {
plugins: (api) => { plugins: api => {
/* /*
If you want to use plugins in your application, include them here: If you want to use plugins in your application, include them here:
......
...@@ -11,15 +11,20 @@ if (process.env.REDIS_URL) { ...@@ -11,15 +11,20 @@ if (process.env.REDIS_URL) {
} }
exports['default'] = { exports['default'] = {
redis: (api) => { redis: api => {
// konstructor: The redis client constructor method. All redis methods must be promises // konstructor: The redis client constructor method. All redis methods must be promises
// args: The arguments to pass to the constructor // args: The arguments to pass to the constructor
// buildNew: is it `new konstructor()` or just `konstructor()`? // buildNew: is it `new konstructor()` or just `konstructor()`?
function retryStrategy (times) { function retryStrategy (times) {
if (times === 1) { if (times === 1) {
const error = 'Unable to connect to Redis - please check your Redis config!' const error =
if (process.env.NODE_ENV === 'test') { console.error(error) } else { api.log(error, 'error') } 'Unable to connect to Redis - please check your Redis config!'
if (process.env.NODE_ENV === 'test') {
console.error(error)
} else {
api.log(error, 'error')
}
return 5000 return 5000
} }
return Math.min(times * 50, maxBackoff) return Math.min(times * 50, maxBackoff)
...@@ -28,20 +33,44 @@ exports['default'] = { ...@@ -28,20 +33,44 @@ exports['default'] = {
return { return {
enabled: true, enabled: true,
'_toExpand': false, _toExpand: false,
client: { client: {
konstructor: require('ioredis'), konstructor: require('ioredis'),
args: [{ port: port, host: host, password: password, db: db, retryStrategy: retryStrategy }], args: [
{
port: port,
host: host,
password: password,
db: db,
retryStrategy: retryStrategy
}
],
buildNew: true buildNew: true
}, },
subscriber: { subscriber: {
konstructor: require('ioredis'), konstructor: require('ioredis'),
args: [{ port: port, host: host, password: password, db: db, retryStrategy: retryStrategy }], args: [
{
port: port,
host: host,
password: password,
db: db,
retryStrategy: retryStrategy
}
],
buildNew: true buildNew: true
}, },
tasks: { tasks: {
konstructor: require('ioredis'), konstructor: require('ioredis'),
args: [{ port: port, host: host, password: password, db: db, retryStrategy: retryStrategy }], args: [
{
port: port,
host: host,
password: password,
db: db,
retryStrategy: retryStrategy
}
],
buildNew: true buildNew: true
} }
} }
......
exports['default'] = { exports['default'] = {
routes: (api) => { routes: api => {
return { return {
get: [ get: [{ path: '/', matchTrailingPathParts: true, action: 'render' }]
{ path: '/', matchTrailingPathParts: true, action: 'render' }
]
} }
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
exports['default'] = { exports['default'] = {
servers: { servers: {
socket: (api) => { socket: api => {
return { return {
enabled: (process.env.ENABLE_TCP_SERVER !== undefined), enabled: process.env.ENABLE_TCP_SERVER !== undefined,
// TCP or TLS? // TCP or TLS?
secure: false, secure: false,
// Passed to tls.createServer if secure=true. Should contain SSL certificates // Passed to tls.createServer if secure=true. Should contain SSL certificates
...@@ -26,7 +26,7 @@ exports['default'] = { ...@@ -26,7 +26,7 @@ exports['default'] = {
exports.test = { exports.test = {
servers: { servers: {
socket: (api) => { socket: api => {
return { return {
enabled: true, enabled: true,
port: 1001 + (process.pid % 64535), port: 1001 + (process.pid % 64535),
......
...@@ -4,7 +4,7 @@ const os = require('os') ...@@ -4,7 +4,7 @@ const os = require('os')
exports['default'] = { exports['default'] = {
servers: { servers: {
web: (api) => { web: api => {
return { return {
enabled: true, enabled: true,
// HTTP or HTTPS? // HTTP or HTTPS?
...@@ -13,7 +13,9 @@ exports['default'] = { ...@@ -13,7 +13,9 @@ exports['default'] = {
serverOptions: {}, serverOptions: {},
// Should we redirect all traffic to the first host in this array if hte request header doesn't match? // Should we redirect all traffic to the first host in this array if hte request header doesn't match?
// i.e.: [ 'https://www.site.com' ] // i.e.: [ 'https://www.site.com' ]
allowedRequestHosts: process.env.ALLOWED_HOSTS ? process.env.ALLOWED_HOSTS.split(',') : [], allowedRequestHosts: process.env.ALLOWED_HOSTS
? process.env.ALLOWED_HOSTS.split(',')
: [],
// Port or Socket Path // Port or Socket Path
port: process.env.PORT || 8080, port: process.env.PORT || 8080,
// Which IP to listen on (use '0.0.0.0' for all; '::' for all on ipv4 and ipv6) // Which IP to listen on (use '0.0.0.0' for all; '::' for all on ipv4 and ipv6)
...@@ -23,7 +25,8 @@ exports['default'] = { ...@@ -23,7 +25,8 @@ exports['default'] = {
httpHeaders: { httpHeaders: {
'X-Powered-By': api.config.general.serverName, 'X-Powered-By': api.config.general.serverName,
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE', 'Access-Control-Allow-Methods':
'HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE',
'Access-Control-Allow-Headers': 'Content-Type' 'Access-Control-Allow-Headers': 'Content-Type'
}, },
// Route that actions will be served from; secondary route against this route will be treated as actions, // Route that actions will be served from; secondary route against this route will be treated as actions,
...@@ -92,7 +95,7 @@ exports['default'] = { ...@@ -92,7 +95,7 @@ exports['default'] = {
exports.production = { exports.production = {
servers: { servers: {
web: (api) => { web: api => {
return { return {
padding: null, padding: null,
metadataOptions: { metadataOptions: {
...@@ -106,7 +109,7 @@ exports.production = { ...@@ -106,7 +109,7 @@ exports.production = {
exports.test = { exports.test = {
servers: { servers: {
web: (api) => { web: api => {
return { return {
secure: false, secure: false,
port: process.env.PORT || 1000 + (process.pid % 64535), port: process.env.PORT || 1000 + (process.pid % 64535),
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
exports['default'] = { exports['default'] = {
servers: { servers: {
websocket: (api) => { websocket: api => {
return { return {
enabled: true, enabled: true,
// you can pass a FQDN (string) here or 'window.location.origin' // you can pass a FQDN (string) here or 'window.location.origin'
...@@ -55,7 +55,7 @@ exports['default'] = { ...@@ -55,7 +55,7 @@ exports['default'] = {
exports['test'] = { exports['test'] = {
servers: { servers: {
websocket: (api) => { websocket: api => {
return { clientUrl: null } return { clientUrl: null }
} }
} }
......
exports['default'] = { exports['default'] = {
tasks: (api) => { tasks: api => {
return { return {
// Should this node run a scheduler to promote delayed tasks? // Should this node run a scheduler to promote delayed tasks?
scheduler: false, scheduler: false,
...@@ -52,7 +52,7 @@ exports['default'] = { ...@@ -52,7 +52,7 @@ exports['default'] = {
} }
exports.test = { exports.test = {
tasks: (api) => { tasks: api => {
return { return {
timeout: 100, timeout: 100,
checkTimeout: 50 checkTimeout: 50
......
'use strict' 'use strict'
const {Initializer, api} = require('actionhero') const { Initializer, api } = require('actionhero')
const next = require('next') const next = require('next')
module.exports = class NextInitializer extends Initializer { module.exports = class NextInitializer extends Initializer {
...@@ -10,18 +10,22 @@ module.exports = class NextInitializer extends Initializer { ...@@ -10,18 +10,22 @@ module.exports = class NextInitializer extends Initializer {
async initialize () { async initialize () {
api.next = { api.next = {
render: async (connection) => { render: async connection => {
if (connection.type !== 'web') { throw new Error('Connections for NEXT apps must be of type "web"') } if (connection.type !== 'web') {
throw new Error('Connections for NEXT apps must be of type "web"')
}
const req = connection.rawConnection.req const req = connection.rawConnection.req
const res = connection.rawConnection.res const res = connection.rawConnection.res
return api.next.handle(req, res) return api.next.handle(req, res)
} }
} }
api.next.dev = (api.env === 'development') api.next.dev = api.env === 'development'
if (api.next.dev) { api.log('Running next in development mode...') } if (api.next.dev) {
api.log('Running next in development mode...')
}
api.next.app = next({dev: api.next.dev}) api.next.app = next({ dev: api.next.dev })
api.next.handle = api.next.app.getRequestHandler() api.next.handle = api.next.app.getRequestHandler()
await api.next.app.prepare() await api.next.app.prepare()
} }
......
...@@ -3,7 +3,15 @@ import Link from 'next/link' ...@@ -3,7 +3,15 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <Link href='/b' as='/a'>
<a>a</a>
</Link>
</li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -3,13 +3,18 @@ import Link from 'next/link' ...@@ -3,13 +3,18 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li>
<li><Link href='/a' as='/b'><a>b</a></Link></li>
<li> <li>
<Link <Link href='/b' as='/a'>
href={{pathname: '/posts', query: { id: '2' }}} <a>a</a>
as='/posts/2' </Link>
> </li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
<li>
<Link href={{ pathname: '/posts', query: { id: '2' } }} as='/posts/2'>
<a>post #2</a> <a>post #2</a>
</Link> </Link>
</li> </li>
......
...@@ -6,12 +6,14 @@ export default class extends Component { ...@@ -6,12 +6,14 @@ export default class extends Component {
} }
render () { render () {
return <div> return (
<div>
<h1>My blog post #{this.props.postId}</h1> <h1>My blog post #{this.props.postId}</h1>
<p> <p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
tempor incididunt ut labore et dolore magna aliqua. eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p> </p>
</div> </div>
)
} }
} }
...@@ -6,8 +6,7 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -6,8 +6,7 @@ const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
const server = express() const server = express()
server.get('/a', (req, res) => { server.get('/a', (req, res) => {
...@@ -26,8 +25,8 @@ app.prepare() ...@@ -26,8 +25,8 @@ app.prepare()
return handle(req, res) return handle(req, res)
}) })
server.listen(port, (err) => { server.listen(port, err => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
...@@ -3,7 +3,15 @@ import Link from 'next/link' ...@@ -3,7 +3,15 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <Link href='/b' as='/a'>
<a>a</a>
</Link>
</li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -6,51 +6,47 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -6,51 +6,47 @@ const dev = process.env.NODE_ENV !== 'production'
fastify.register((fastify, opts, next) => { fastify.register((fastify, opts, next) => {
const app = Next({ dev }) const app = Next({ dev })
app.prepare() app
.prepare()
.then(() => { .then(() => {
if (dev) { if (dev) {
fastify.get('/_next/*', (req, reply) => { fastify.get('/_next/*', (req, reply) => {
return app.handleRequest(req.req, reply.res) return app.handleRequest(req.req, reply.res).then(() => {
.then(() => {
reply.sent = true reply.sent = true
}) })
}) })
} }
fastify.get('/a', (req, reply) => { fastify.get('/a', (req, reply) => {
return app.render(req.req, reply.res, '/b', req.query) return app.render(req.req, reply.res, '/b', req.query).then(() => {
.then(() => {
reply.sent = true reply.sent = true
}) })
}) })
fastify.get('/b', (req, reply) => { fastify.get('/b', (req, reply) => {
return app.render(req.req, reply.res, '/a', req.query) return app.render(req.req, reply.res, '/a', req.query).then(() => {
.then(() => {
reply.sent = true reply.sent = true
}) })
}) })
fastify.get('/*', (req, reply) => { fastify.get('/*', (req, reply) => {
return app.handleRequest(req.req, reply.res) return app.handleRequest(req.req, reply.res).then(() => {
.then(() => {
reply.sent = true reply.sent = true
}) })
}) })
fastify.setNotFoundHandler((request, reply) => { fastify.setNotFoundHandler((request, reply) => {
return app.render404(request.req, reply.res) return app.render404(request.req, reply.res).then(() => {
.then(() => {
reply.sent = true reply.sent = true
}) })
}) })
next() next()
}) })
.catch((err) => next(err)) .catch(err => next(err))
}) })
fastify.listen(port, (err) => { fastify.listen(port, err => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
...@@ -13,7 +13,13 @@ const defaultHandlerWrapper = app => async ({ raw: { req, res }, url }) => { ...@@ -13,7 +13,13 @@ const defaultHandlerWrapper = app => async ({ raw: { req, res }, url }) => {
} }
const pathWrapper = (app, pathName, opts) => async ({ raw, query, params }) => { const pathWrapper = (app, pathName, opts) => async ({ raw, query, params }) => {
return app.renderToHTML(raw.req, raw.res, pathName, { ...query, ...params }, opts) return app.renderToHTML(
raw.req,
raw.res,
pathName,
{ ...query, ...params },
opts
)
} }
module.exports = { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper } module.exports = { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper }
...@@ -3,7 +3,15 @@ import Link from 'next/link' ...@@ -3,7 +3,15 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <Link href='/b' as='/a'>
<a>a</a>
</Link>
</li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
</ul> </ul>
) )
const next = require('next') const next = require('next')
const Hapi = require('hapi') const Hapi = require('hapi')
const { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper } = require('./next-wrapper') const {
pathWrapper,
defaultHandlerWrapper,
nextHandlerWrapper
} = require('./next-wrapper')
const port = parseInt(process.env.PORT, 10) || 3000 const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production' const dev = process.env.NODE_ENV !== 'production'
...@@ -9,9 +13,7 @@ const server = new Hapi.Server({ ...@@ -9,9 +13,7 @@ const server = new Hapi.Server({
port port
}) })
app app.prepare().then(async () => {
.prepare()
.then(async () => {
server.route({ server.route({
method: 'GET', method: 'GET',
path: '/a', path: '/a',
...@@ -26,13 +28,13 @@ app ...@@ -26,13 +28,13 @@ app
server.route({ server.route({
method: 'GET', method: 'GET',
path: '/_next/{p*}', /* next specific routes */ path: '/_next/{p*}' /* next specific routes */,
handler: nextHandlerWrapper(app) handler: nextHandlerWrapper(app)
}) })
server.route({ server.route({
method: 'GET', method: 'GET',
path: '/{p*}', /* catch all route */ path: '/{p*}' /* catch all route */,
handler: defaultHandlerWrapper(app) handler: defaultHandlerWrapper(app)
}) })
...@@ -43,4 +45,4 @@ app ...@@ -43,4 +45,4 @@ app
console.log('Error starting server') console.log('Error starting server')
console.log(error) console.log(error)
} }
}) })
...@@ -3,7 +3,15 @@ import Link from 'next/link' ...@@ -3,7 +3,15 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <Link href='/b' as='/a'>
<a>a</a>
</Link>
</li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -7,8 +7,7 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -7,8 +7,7 @@ const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
const server = new Koa() const server = new Koa()
const router = new Router() const router = new Router()
...@@ -36,4 +35,4 @@ app.prepare() ...@@ -36,4 +35,4 @@ app.prepare()
server.listen(port, () => { server.listen(port, () => {
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
...@@ -3,7 +3,15 @@ import Link from 'next/link' ...@@ -3,7 +3,15 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <Link href='/b' as='/a'>
<a>a</a>
</Link>
</li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -3,7 +3,15 @@ import Link from 'next/link' ...@@ -3,7 +3,15 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <Link href='/b' as='/a'>
<a>a</a>
</Link>
</li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -7,8 +7,7 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -7,8 +7,7 @@ const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const parsedUrl = parse(req.url, true) const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl const { pathname, query } = parsedUrl
...@@ -20,9 +19,8 @@ app.prepare() ...@@ -20,9 +19,8 @@ app.prepare()
} else { } else {
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
} }
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
...@@ -3,7 +3,15 @@ import Link from 'next/link' ...@@ -3,7 +3,15 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <Link href='/b' as='/a'>
<a>a</a>
</Link>
</li>
<li>
<Link href='/a' as='/b'>
<a>b</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -7,8 +7,7 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -7,8 +7,7 @@ const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const parsedUrl = parse(req.url, true) const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl const { pathname, query } = parsedUrl
...@@ -20,9 +19,8 @@ app.prepare() ...@@ -20,9 +19,8 @@ app.prepare()
} else { } else {
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
} }
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
...@@ -14,7 +14,9 @@ export default class Index extends React.Component { ...@@ -14,7 +14,9 @@ export default class Index extends React.Component {
return ( return (
<div> <div>
<p>Next.js has {this.props.stars} ⭐️</p> <p>Next.js has {this.props.stars} ⭐️</p>
<Link prefetch href='/preact'><a>How about preact?</a></Link> <Link prefetch href='/preact'>
<a>How about preact?</a>
</Link>
</div> </div>
) )
} }
......
...@@ -14,7 +14,9 @@ export default class Preact extends React.Component { ...@@ -14,7 +14,9 @@ export default class Preact extends React.Component {
return ( return (
<div> <div>
<p>Preact has {this.props.stars} ⭐️</p> <p>Preact has {this.props.stars} ⭐️</p>
<Link prefetch href='/'><a>I bet next has more stars (?)</a></Link> <Link prefetch href='/'>
<a>I bet next has more stars (?)</a>
</Link>
</div> </div>
) )
} }
......
import { INPUT_VALUE } from '../constants' import { INPUT_VALUE } from '../constants'
export const inputChange = (title, name, val) => dispatch => { export const inputChange = (title, name, val) => dispatch => {
return dispatch({type: INPUT_VALUE, title, name, val}) return dispatch({ type: INPUT_VALUE, title, name, val })
} }
import React, {Component} from 'react' import React, { Component } from 'react'
import { Col, Row } from 'react-bootstrap' import { Col, Row } from 'react-bootstrap'
import { connect } from 'react-redux' import { connect } from 'react-redux'
...@@ -9,7 +9,7 @@ class DisplayForm extends Component { ...@@ -9,7 +9,7 @@ class DisplayForm extends Component {
<div> <div>
<Row> <Row>
<Col lg={8} lgOffset={2}> <Col lg={8} lgOffset={2}>
<pre>{JSON.stringify(state, null, 2) }</pre> <pre>{JSON.stringify(state, null, 2)}</pre>
</Col> </Col>
</Row> </Row>
</div> </div>
......
...@@ -6,7 +6,7 @@ const Header = () => { ...@@ -6,7 +6,7 @@ const Header = () => {
<Row style={{ marginTop: '10px' }}> <Row style={{ marginTop: '10px' }}>
<Col lg={8} lgOffset={2}> <Col lg={8} lgOffset={2}>
<Jumbotron style={{ borderRadius: '15px' }}> <Jumbotron style={{ borderRadius: '15px' }}>
<h1 style={{textAlign: 'center'}}>Form Handler</h1> <h1 style={{ textAlign: 'center' }}>Form Handler</h1>
</Jumbotron> </Jumbotron>
</Col> </Col>
</Row> </Row>
......
...@@ -16,7 +16,12 @@ const UserForm = () => { ...@@ -16,7 +16,12 @@ const UserForm = () => {
<Input controlLabel='Email' type='email' title='user' name='email' /> <Input controlLabel='Email' type='email' title='user' name='email' />
</Col> </Col>
<Col lg={8} lgOffset={4}> <Col lg={8} lgOffset={4}>
<Input controlLabel='Password' type='password' title='user' name='password' /> <Input
controlLabel='Password'
type='password'
title='user'
name='password'
/>
</Col> </Col>
</Row> </Row>
</div> </div>
......
import React, {Component} from 'react' import React, { Component } from 'react'
import Head from 'next/head' import Head from 'next/head'
import { Col, Row } from 'react-bootstrap' import { Col, Row } from 'react-bootstrap'
...@@ -14,7 +14,10 @@ class Main extends Component { ...@@ -14,7 +14,10 @@ class Main extends Component {
<div> <div>
<Head> <Head>
<title>Form Handler</title> <title>Form Handler</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css' /> <link
rel='stylesheet'
href='https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css'
/>
</Head> </Head>
<Header /> <Header />
<DisplayForm /> <DisplayForm />
......
import React, {Component} from 'react' import React, { Component } from 'react'
import { FormGroup, ControlLabel, FormControl } from 'react-bootstrap' import { FormGroup, ControlLabel, FormControl } from 'react-bootstrap'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
...@@ -6,7 +6,7 @@ import { bindActionCreators } from 'redux' ...@@ -6,7 +6,7 @@ import { bindActionCreators } from 'redux'
import { inputChange } from '../actions' import { inputChange } from '../actions'
class Input extends Component { class Input extends Component {
inputChange = (e) => { inputChange = e => {
const { inputChange, title, name } = this.props const { inputChange, title, name } = this.props
inputChange(title, name, e.target.value) inputChange(title, name, e.target.value)
} }
...@@ -35,4 +35,7 @@ const mapDispatchToProps = dispatch => { ...@@ -35,4 +35,7 @@ const mapDispatchToProps = dispatch => {
} }
} }
export default connect(null, mapDispatchToProps)(Input) export default connect(
null,
mapDispatchToProps
)(Input)
...@@ -3,11 +3,9 @@ import { INPUT_VALUE } from '../constants' ...@@ -3,11 +3,9 @@ import { INPUT_VALUE } from '../constants'
export default (state = {}, action) => { export default (state = {}, action) => {
switch (action.type) { switch (action.type) {
case INPUT_VALUE: case INPUT_VALUE:
return { ...state, return {
[action.title]: ...state,
{ ...state[action.title], [action.title]: { ...state[action.title], [action.name]: action.val }
[action.name]: action.val
}
} }
default: default:
return state return state
......
...@@ -5,7 +5,8 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -5,7 +5,8 @@ const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app
.prepare()
.then(() => { .then(() => {
const server = express() const server = express()
...@@ -17,12 +18,12 @@ app.prepare() ...@@ -17,12 +18,12 @@ app.prepare()
return handle(req, res) return handle(req, res)
}) })
server.listen(3000, (err) => { server.listen(3000, err => {
if (err) throw err if (err) throw err
console.log('> Ready on http://localhost:3000') console.log('> Ready on http://localhost:3000')
}) })
}) })
.catch((ex) => { .catch(ex => {
console.error(ex.stack) console.error(ex.stack)
process.exit(1) process.exit(1)
}) })
const env = require('./env-config') const env = require('./env-config')
module.exports = { module.exports = {
'presets': [ presets: ['next/babel'],
'next/babel' plugins: [['transform-define', env]]
],
'plugins': [
['transform-define', env]
]
} }
...@@ -2,6 +2,11 @@ import Link from 'next/link' ...@@ -2,6 +2,11 @@ import Link from 'next/link'
export default () => ( export default () => (
<div> <div>
<div>About us</div> <div>About us</div>
<div>Back to <Link href='/' as={process.env.BACKEND_URL + '/'}><a>Home</a></Link></div> <div>
Back to{' '}
<Link href='/' as={process.env.BACKEND_URL + '/'}>
<a>Home</a>
</Link>
</div>
</div> </div>
) )
import Link from 'next/link' import Link from 'next/link'
export default () => ( export default () => (
<div>Hello World. <Link href='/about' as={process.env.BACKEND_URL + '/about'}><a>About</a></Link></div> <div>
Hello World.{' '}
<Link href='/about' as={process.env.BACKEND_URL + '/about'}>
<a>About</a>
</Link>
</div>
) )
export default () => ( export default () => <div>About us</div>
<div>About us</div>
)
export default () => ( export default () => <div>Hello Day</div>
<div>Hello Day</div>
)
import Link from 'next/link' import Link from 'next/link'
export default () => ( export default () => (
<div>Hello World. <Link href='/about'><a>About</a></Link></div> <div>
Hello World.{' '}
<Link href='/about'>
<a>About</a>
</Link>
</div>
) )
...@@ -4,22 +4,28 @@ import Head from 'next/head' ...@@ -4,22 +4,28 @@ import Head from 'next/head'
export default ({ children, title = 'This is the default title' }) => ( export default ({ children, title = 'This is the default title' }) => (
<div> <div>
<Head> <Head>
<title>{ title }</title> <title>{title}</title>
<meta charSet='utf-8' /> <meta charSet='utf-8' />
<meta name='viewport' content='initial-scale=1.0, width=device-width' /> <meta name='viewport' content='initial-scale=1.0, width=device-width' />
</Head> </Head>
<header> <header>
<nav> <nav>
<Link href='/'><a>Home</a></Link> | <Link href='/'>
<Link href='/about'><a>About</a></Link> | <a>Home</a>
<Link href='/contact'><a>Contact</a></Link> </Link>{' '}
|
<Link href='/about'>
<a>About</a>
</Link>{' '}
|
<Link href='/contact'>
<a>Contact</a>
</Link>
</nav> </nav>
</header> </header>
{ children } {children}
<footer> <footer>{'I`m here to stay'}</footer>
{'I`m here to stay'}
</footer>
</div> </div>
) )
export default ({ title, children }) => ( export default ({ title, children }) => (
<div className='main'> <div className='main'>
<h1>{ title }</h1> <h1>{title}</h1>
{ children } {children}
<style jsx>{` <style jsx>{`
.main { .main {
font: 15px Helvetica, Arial; font: 15px Helvetica, Arial;
......
...@@ -37,7 +37,7 @@ export default () => ( ...@@ -37,7 +37,7 @@ export default () => (
} }
hr::before { hr::before {
content: "***"; content: '***';
color: #ccc; color: #ccc;
} }
`}</style> `}</style>
......
...@@ -5,8 +5,9 @@ export default dynamic({ ...@@ -5,8 +5,9 @@ export default dynamic({
BarChart: import('recharts').then(({ BarChart }) => BarChart), BarChart: import('recharts').then(({ BarChart }) => BarChart),
Bar: import('recharts').then(({ Bar }) => Bar) Bar: import('recharts').then(({ Bar }) => Bar)
}), }),
render: (props, { BarChart, Bar }) => render: (props, { BarChart, Bar }) => (
<BarChart width={props.width} height={props.height} data={props.data}> <BarChart width={props.width} height={props.height} data={props.data}>
<Bar dataKey='uv' fill='#8884d8' /> <Bar dataKey='uv' fill='#8884d8' />
</BarChart> </BarChart>
)
}) })
...@@ -5,8 +5,9 @@ export default dynamic({ ...@@ -5,8 +5,9 @@ export default dynamic({
LineChart: import('recharts').then(({ LineChart }) => LineChart), LineChart: import('recharts').then(({ LineChart }) => LineChart),
Line: import('recharts').then(({ Line }) => Line) Line: import('recharts').then(({ Line }) => Line)
}), }),
render: (props, { LineChart, Line }) => render: (props, { LineChart, Line }) => (
<LineChart width={props.width} height={props.height} data={props.data}> <LineChart width={props.width} height={props.height} data={props.data}>
<Line type='monotone' dataKey='uv' stroke='#8884d8' /> <Line type='monotone' dataKey='uv' stroke='#8884d8' />
</LineChart> </LineChart>
)
}) })
...@@ -2,13 +2,13 @@ import React from 'react' ...@@ -2,13 +2,13 @@ import React from 'react'
import BarChart from '../components/BarChart' import BarChart from '../components/BarChart'
const data = [ const data = [
{name: 'Page A', uv: 4000, pv: 2400, amt: 2400}, { name: 'Page A', uv: 4000, pv: 2400, amt: 2400 },
{name: 'Page B', uv: 3000, pv: 1398, amt: 2210}, { name: 'Page B', uv: 3000, pv: 1398, amt: 2210 },
{name: 'Page C', uv: 2000, pv: 9800, amt: 2290}, { name: 'Page C', uv: 2000, pv: 9800, amt: 2290 },
{name: 'Page D', uv: 2780, pv: 3908, amt: 2000}, { name: 'Page D', uv: 2780, pv: 3908, amt: 2000 },
{name: 'Page E', uv: 1890, pv: 4800, amt: 2181}, { name: 'Page E', uv: 1890, pv: 4800, amt: 2181 },
{name: 'Page F', uv: 2390, pv: 3800, amt: 2500}, { name: 'Page F', uv: 2390, pv: 3800, amt: 2500 },
{name: 'Page G', uv: 3490, pv: 4300, amt: 2100} { name: 'Page G', uv: 3490, pv: 4300, amt: 2100 }
] ]
const Chart = () => ( const Chart = () => (
......
...@@ -3,13 +3,13 @@ import Link from 'next/link' ...@@ -3,13 +3,13 @@ import Link from 'next/link'
import LineChart from '../components/LineChart' import LineChart from '../components/LineChart'
const data = [ const data = [
{name: 'Page A', uv: 1000, pv: 2400, amt: 2400}, { name: 'Page A', uv: 1000, pv: 2400, amt: 2400 },
{name: 'Page B', uv: 3000, pv: 1398, amt: 2210}, { name: 'Page B', uv: 3000, pv: 1398, amt: 2210 },
{name: 'Page C', uv: 2000, pv: 9800, amt: 2290}, { name: 'Page C', uv: 2000, pv: 9800, amt: 2290 },
{name: 'Page D', uv: 2780, pv: 3908, amt: 2000}, { name: 'Page D', uv: 2780, pv: 3908, amt: 2000 },
{name: 'Page E', uv: 1890, pv: 4800, amt: 2181}, { name: 'Page E', uv: 1890, pv: 4800, amt: 2181 },
{name: 'Page F', uv: 2390, pv: 3800, amt: 2500}, { name: 'Page F', uv: 2390, pv: 3800, amt: 2500 },
{name: 'Page G', uv: 3490, pv: 4300, amt: 2100} { name: 'Page G', uv: 3490, pv: 4300, amt: 2100 }
] ]
const Index = () => ( const Index = () => (
......
...@@ -6,12 +6,14 @@ export default class extends React.Component { ...@@ -6,12 +6,14 @@ export default class extends React.Component {
} }
render () { render () {
return <div> return (
<div>
<h1>My {this.props.id} blog post</h1> <h1>My {this.props.id} blog post</h1>
<p> <p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
tempor incididunt ut labore et dolore magna aliqua. eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p> </p>
</div> </div>
)
} }
} }
...@@ -2,8 +2,20 @@ import Link from 'next/link' ...@@ -2,8 +2,20 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/blog?id=first' as='/blog/first'><a>My first blog post</a></Link></li> <li>
<li><Link href='/blog?id=second' as='/blog/second'><a>My second blog post</a></Link></li> <Link href='/blog?id=first' as='/blog/first'>
<li><Link href='/blog?id=last' as='/blog/last'><a>My last blog post</a></Link></li> <a>My first blog post</a>
</Link>
</li>
<li>
<Link href='/blog?id=second' as='/blog/second'>
<a>My second blog post</a>
</Link>
</li>
<li>
<Link href='/blog?id=last' as='/blog/last'>
<a>My last blog post</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -10,8 +10,7 @@ const handle = app.getRequestHandler() ...@@ -10,8 +10,7 @@ const handle = app.getRequestHandler()
const route = pathMatch() const route = pathMatch()
const match = route('/blog/:id') const match = route('/blog/:id')
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const { pathname, query } = parse(req.url, true) const { pathname, query } = parse(req.url, true)
const params = match(pathname) const params = match(pathname)
...@@ -23,9 +22,8 @@ app.prepare() ...@@ -23,9 +22,8 @@ app.prepare()
// get the query string passed to our application // get the query string passed to our application
// i.e. /blog/foo?show-comments=true // i.e. /blog/foo?show-comments=true
app.render(req, res, '/blog', Object.assign(params, query)) app.render(req, res, '/blog', Object.assign(params, query))
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
...@@ -3,6 +3,10 @@ import Link from 'next/link' ...@@ -3,6 +3,10 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/item'><a>View Item</a></Link></li> <li>
<Link href='/item'>
<a>View Item</a>
</Link>
</li>
</ul> </ul>
) )
import {Component} from 'react' import { Component } from 'react'
import Link from 'next/link' import Link from 'next/link'
import fetch from 'isomorphic-unfetch' import fetch from 'isomorphic-unfetch'
...@@ -15,7 +15,9 @@ export default class extends Component { ...@@ -15,7 +15,9 @@ export default class extends Component {
return { item: query.itemData } return { item: query.itemData }
} else { } else {
// On the client, we should fetch the data remotely // On the client, we should fetch the data remotely
const res = await fetch('/_data/item', {headers: {'Accept': 'application/json'}}) const res = await fetch('/_data/item', {
headers: { Accept: 'application/json' }
})
const json = await res.json() const json = await res.json()
return { item: json } return { item: json }
} }
...@@ -24,9 +26,15 @@ export default class extends Component { ...@@ -24,9 +26,15 @@ export default class extends Component {
render () { render () {
return ( return (
<div className='item'> <div className='item'>
<div><Link href='/'><a>Back Home</a></Link></div> <div>
<Link href='/'>
<a>Back Home</a>
</Link>
</div>
<h1>{this.props.item.title}</h1> <h1>{this.props.item.title}</h1>
<h2>{this.props.item.subtitle} - {this.props.item.seller}</h2> <h2>
{this.props.item.subtitle} - {this.props.item.seller}
</h2>
</div> </div>
) )
} }
......
...@@ -32,7 +32,7 @@ app.prepare().then(() => { ...@@ -32,7 +32,7 @@ app.prepare().then(() => {
return handle(req, res) return handle(req, res)
}) })
server.listen(3000, (err) => { server.listen(3000, err => {
if (err) throw err if (err) throw err
console.log('> Ready on http://localhost:3000') console.log('> Ready on http://localhost:3000')
}) })
......
...@@ -5,9 +5,7 @@ import Loading from '../components/Loading' ...@@ -5,9 +5,7 @@ import Loading from '../components/Loading'
export default () => ( export default () => (
<main> <main>
<section> <section>
<h1> <h1>This section is server-side rendered.</h1>
This section is server-side rendered.
</h1>
</section> </section>
<NoSSR onSSR={<Loading />}> <NoSSR onSSR={<Loading />}>
......
export default () => ( export default () => (
<ul> <ul>
<li><a href='/robots.txt'>/robots.txt</a></li> <li>
<li><a href='/sitemap.xml'>/sitemap.xml</a></li> <a href='/robots.txt'>/robots.txt</a>
<li><a href='/favicon.ico'>/favicon.ico</a></li> </li>
<li>
<a href='/sitemap.xml'>/sitemap.xml</a>
</li>
<li>
<a href='/favicon.ico'>/favicon.ico</a>
</li>
</ul> </ul>
) )
...@@ -8,24 +8,18 @@ const dev = process.env.NODE_ENV !== 'production' ...@@ -8,24 +8,18 @@ const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const parsedUrl = parse(req.url, true) const parsedUrl = parse(req.url, true)
const rootStaticFiles = [ const rootStaticFiles = ['/robots.txt', '/sitemap.xml', '/favicon.ico']
'/robots.txt',
'/sitemap.xml',
'/favicon.ico'
]
if (rootStaticFiles.indexOf(parsedUrl.pathname) > -1) { if (rootStaticFiles.indexOf(parsedUrl.pathname) > -1) {
const path = join(__dirname, 'static', parsedUrl.pathname) const path = join(__dirname, 'static', parsedUrl.pathname)
app.serveStatic(req, res, path) app.serveStatic(req, res, path)
} else { } else {
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
} }
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
...@@ -3,11 +3,11 @@ import Link from 'next/link' ...@@ -3,11 +3,11 @@ import Link from 'next/link'
export default () => ( export default () => (
<div> <div>
<Link href='/'> <Link href='/'>
<a style={styles.a} >Home</a> <a style={styles.a}>Home</a>
</Link> </Link>
<Link href='/about'> <Link href='/about'>
<a style={styles.a} >About</a> <a style={styles.a}>About</a>
</Link> </Link>
</div> </div>
) )
......
...@@ -6,12 +6,14 @@ export default class extends React.Component { ...@@ -6,12 +6,14 @@ export default class extends React.Component {
} }
render () { render () {
return <div> return (
<div>
<h1>My {this.props.id} blog post</h1> <h1>My {this.props.id} blog post</h1>
<p> <p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
tempor incididunt ut labore et dolore magna aliqua. eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p> </p>
</div> </div>
)
} }
} }
...@@ -2,8 +2,20 @@ import Link from 'next/link' ...@@ -2,8 +2,20 @@ import Link from 'next/link'
export default () => ( export default () => (
<ul> <ul>
<li><Link href='/blog?id=first' as='/blog/first'><a>My first blog post</a></Link></li> <li>
<li><Link href='/blog?id=second' as='/blog/second'><a>My second blog post</a></Link></li> <Link href='/blog?id=first' as='/blog/first'>
<li><Link href='/blog?id=last' as='/blog/last'><a>My last blog post</a></Link></li> <a>My first blog post</a>
</Link>
</li>
<li>
<Link href='/blog?id=second' as='/blog/second'>
<a>My second blog post</a>
</Link>
</li>
<li>
<Link href='/blog?id=last' as='/blog/last'>
<a>My last blog post</a>
</Link>
</li>
</ul> </ul>
) )
...@@ -16,8 +16,7 @@ const ssrCache = new LRUCache({ ...@@ -16,8 +16,7 @@ const ssrCache = new LRUCache({
maxAge: 1000 * 60 * 60 // 1hour maxAge: 1000 * 60 * 60 // 1hour
}) })
app.prepare() app.prepare().then(() => {
.then(() => {
const server = express() const server = express()
// Use the `renderAndCache` utility defined below to serve pages // Use the `renderAndCache` utility defined below to serve pages
...@@ -34,11 +33,11 @@ app.prepare() ...@@ -34,11 +33,11 @@ app.prepare()
return handle(req, res) return handle(req, res)
}) })
server.listen(port, (err) => { server.listen(port, err => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
/* /*
* NB: make sure to modify this to take into account anything that should trigger * NB: make sure to modify this to take into account anything that should trigger
......
...@@ -7,7 +7,7 @@ module.exports = { ...@@ -7,7 +7,7 @@ module.exports = {
} }
config.resolve.alias = { config.resolve.alias = {
'react': 'inferno-compat', react: 'inferno-compat',
'react-dom': 'inferno-compat' 'react-dom': 'inferno-compat'
} }
return config return config
......
import React from 'react' import React from 'react'
export default () => ( export default () => <div>About us</div>
<div>About us</div>
)
...@@ -2,5 +2,10 @@ import React from 'react' ...@@ -2,5 +2,10 @@ import React from 'react'
import Link from 'next/link' import Link from 'next/link'
export default () => ( export default () => (
<div>Hello World. <Link prefetch href='/about'><a>About</a></Link></div> <div>
Hello World.{' '}
<Link prefetch href='/about'>
<a>About</a>
</Link>
</div>
) )
...@@ -17,14 +17,12 @@ const next = require('next') ...@@ -17,14 +17,12 @@ const next = require('next')
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const parsedUrl = parse(req.url, true) const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
import React from 'react' import React from 'react'
export default () => ( export default () => <div>About us</div>
<div>About us</div>
)
...@@ -2,5 +2,10 @@ import React from 'react' ...@@ -2,5 +2,10 @@ import React from 'react'
import Link from 'next/link' import Link from 'next/link'
export default () => ( export default () => (
<div>Hello World. <Link href='/about'><a>About</a></Link></div> <div>
Hello World.{' '}
<Link href='/about'>
<a>About</a>
</Link>
</div>
) )
...@@ -16,14 +16,12 @@ const next = require('next') ...@@ -16,14 +16,12 @@ const next = require('next')
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const parsedUrl = parse(req.url, true) const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
import React from 'react' import React from 'react'
export default () => ( export default () => <div>About us</div>
<div>About us</div>
)
...@@ -2,5 +2,10 @@ import React from 'react' ...@@ -2,5 +2,10 @@ import React from 'react'
import Link from 'next/link' import Link from 'next/link'
export default () => ( export default () => (
<div>Hello World. <Link href='/about'><a>About</a></Link></div> <div>
Hello World.{' '}
<Link href='/about'>
<a>About</a>
</Link>
</div>
) )
...@@ -10,14 +10,12 @@ const next = require('next') ...@@ -10,14 +10,12 @@ const next = require('next')
const app = next({ dev }) const app = next({ dev })
const handle = app.getRequestHandler() const handle = app.getRequestHandler()
app.prepare() app.prepare().then(() => {
.then(() => {
createServer((req, res) => { createServer((req, res) => {
const parsedUrl = parse(req.url, true) const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl) handle(req, res, parsedUrl)
}) }).listen(port, err => {
.listen(port, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
}) })
...@@ -13,7 +13,7 @@ export default () => ( ...@@ -13,7 +13,7 @@ export default () => (
// and use it manually // and use it manually
function onClickHandler (href) { function onClickHandler (href) {
return (e) => { return e => {
e.preventDefault() e.preventDefault()
Router.push(href) Router.push(href)
} }
......
import {Component} from 'react' import { Component } from 'react'
import Header from '../components/Header' import Header from '../components/Header'
import Router from 'next/router' import Router from 'next/router'
......
...@@ -10,7 +10,7 @@ const ActiveLink = ({ children, router, href }) => { ...@@ -10,7 +10,7 @@ const ActiveLink = ({ children, router, href }) => {
color: router.pathname === href ? 'red' : 'black' color: router.pathname === href ? 'red' : 'black'
} }
const handleClick = (e) => { const handleClick = e => {
e.preventDefault() e.preventDefault()
router.push(href) router.push(href)
} }
......
import {Component} from 'react' import { Component } from 'react'
import Header from '../components/Header' import Header from '../components/Header'
import Router from 'next/router' import Router from 'next/router'
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
} from 'react-instantsearch/dom' } from 'react-instantsearch/dom'
import { InstantSearch } from './instantsearch' import { InstantSearch } from './instantsearch'
const HitComponent = ({ hit }) => const HitComponent = ({ hit }) => (
<div className='hit'> <div className='hit'>
<div> <div>
<div className='hit-picture'> <div className='hit-picture'>
...@@ -20,12 +20,8 @@ const HitComponent = ({ hit }) => ...@@ -20,12 +20,8 @@ const HitComponent = ({ hit }) =>
<div className='hit-content'> <div className='hit-content'>
<div> <div>
<Highlight attributeName='name' hit={hit} /> <Highlight attributeName='name' hit={hit} />
<span> <span> - ${hit.price}</span>
{' '}- ${hit.price} <span> - {hit.rating} stars</span>
</span>
<span>
{' '}- {hit.rating} stars
</span>
</div> </div>
<div className='hit-type'> <div className='hit-type'>
<Highlight attributeName='type' hit={hit} /> <Highlight attributeName='type' hit={hit} />
...@@ -35,6 +31,7 @@ const HitComponent = ({ hit }) => ...@@ -35,6 +31,7 @@ const HitComponent = ({ hit }) =>
</div> </div>
</div> </div>
</div> </div>
)
HitComponent.propTypes = { HitComponent.propTypes = {
hit: PropTypes.object hit: PropTypes.object
...@@ -45,7 +42,7 @@ export default class extends React.Component { ...@@ -45,7 +42,7 @@ export default class extends React.Component {
searchState: PropTypes.object, searchState: PropTypes.object,
resultsState: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), resultsState: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
onSearchStateChange: PropTypes.func onSearchStateChange: PropTypes.func
}; }
render () { render () {
return ( return (
......
...@@ -6,7 +6,7 @@ const defaultDescription = '' ...@@ -6,7 +6,7 @@ const defaultDescription = ''
const defaultOGURL = '' const defaultOGURL = ''
const defaultOGImage = '' const defaultOGImage = ''
export const Head = props => export const Head = props => (
<NextHead> <NextHead>
<meta charSet='UTF-8' /> <meta charSet='UTF-8' />
<title>{props.title || ''}</title> <title>{props.title || ''}</title>
...@@ -37,6 +37,7 @@ export const Head = props => ...@@ -37,6 +37,7 @@ export const Head = props =>
/> />
<link rel='stylesheet' href='../static/instantsearch.css' /> <link rel='stylesheet' href='../static/instantsearch.css' />
</NextHead> </NextHead>
)
Head.propTypes = { Head.propTypes = {
title: string, title: string,
......
...@@ -13,7 +13,7 @@ export default class extends React.Component { ...@@ -13,7 +13,7 @@ export default class extends React.Component {
static propTypes = { static propTypes = {
resultsState: PropTypes.object, resultsState: PropTypes.object,
searchState: PropTypes.object searchState: PropTypes.object
}; }
constructor (props) { constructor (props) {
super(props) super(props)
...@@ -42,7 +42,7 @@ export default class extends React.Component { ...@@ -42,7 +42,7 @@ export default class extends React.Component {
}) })
}, updateAfter) }, updateAfter)
this.setState({ searchState }) this.setState({ searchState })
}; }
componentDidMount () { componentDidMount () {
this.setState({ searchState: qs.parse(window.location.search.slice(1)) }) this.setState({ searchState: qs.parse(window.location.search.slice(1)) })
......
export default ({ author }) => ( export default ({ author }) => <div className='byline'>By {author}</div>
<div className='byline'>
By {author}
</div>
)
...@@ -8,8 +8,14 @@ export default class MyDocument extends Document { ...@@ -8,8 +8,14 @@ export default class MyDocument extends Document {
<Head> <Head>
<link rel='canonical' href='/' /> <link rel='canonical' href='/' />
<meta name='viewport' content='width=device-width,minimum-scale=1' /> <meta name='viewport' content='width=device-width,minimum-scale=1' />
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto' /> <link
<style amp-boilerplate=''>{`body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}`}</style><noscript><style amp-boilerplate=''>{`body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}`}</style></noscript> rel='stylesheet'
href='https://fonts.googleapis.com/css?family=Roboto'
/>
<style amp-boilerplate=''>{`body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}`}</style>
<noscript>
<style amp-boilerplate=''>{`body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}`}</style>
</noscript>
<style amp-custom=''>{`body {font-family: Roboto, sans-serif; padding: 30px; color: #444;} h1 {margin-bottom: 5px;} .byline { color: #aaa; margin-bottom: 25px; } p {font-size: 18px; line-height: 30px; margin-top: 30px;} .caption {color: #ccc; margin-top: 0; font-size: 14px; text-align: center;}`}</style> <style amp-custom=''>{`body {font-family: Roboto, sans-serif; padding: 30px; color: #444;} h1 {margin-bottom: 5px;} .byline { color: #aaa; margin-bottom: 25px; } p {font-size: 18px; line-height: 30px; margin-top: 30px;} .caption {color: #ccc; margin-top: 0; font-size: 14px; text-align: center;}`}</style>
<script async src='https://cdn.ampproject.org/v0.js' /> <script async src='https://cdn.ampproject.org/v0.js' />
</Head> </Head>
......
...@@ -8,12 +8,76 @@ export default () => ( ...@@ -8,12 +8,76 @@ export default () => (
</Head> </Head>
<h1>The Dog</h1> <h1>The Dog</h1>
<Byline author='Meow Meow Fuzzyface' /> <Byline author='Meow Meow Fuzzyface' />
<amp-img src='/static/dog.jpg' width='470' height='350' layout='responsive' alt='Woof' /> <amp-img
src='/static/dog.jpg'
width='470'
height='350'
layout='responsive'
alt='Woof'
/>
<p className='caption'>Woooooooooooof</p> <p className='caption'>Woooooooooooof</p>
<p>Wafer donut candy soufflé lemon drops icing. Marzipan gummi bears pie danish lollipop pudding powder gummi bears sweet. Pie sweet roll sweet roll topping chocolate bar dragée pudding chocolate cake. Croissant sweet chocolate bar cheesecake candy canes. Tootsie roll icing macaroon bonbon cupcake apple pie candy canes biscuit candy canes. Jujubes jelly liquorice toffee gingerbread. Candy tootsie roll macaroon chocolate bar icing sugar plum pie. Icing gummies chocolate bar chocolate marzipan bonbon cookie chocolate tart. Caramels danish halvah croissant. Cheesecake cookie tootsie roll ice cream. Powder dessert carrot cake muffin tiramisu lemon drops liquorice topping brownie. Soufflé chocolate cake croissant cupcake jelly.</p> <p>
<p>Muffin gummies dessert cheesecake candy canes. Candy canes danish cotton candy tart dessert powder bear claw marshmallow. Muffin chocolate marshmallow danish. Chocolate bar biscuit cake tiramisu. Topping sweet brownie jujubes powder marzipan. Croissant wafer bonbon chupa chups cake cake marzipan caramels jujubes. Cupcake cheesecake sweet roll marshmallow lollipop danish jujubes jelly icing. Apple pie chupa chups lollipop jelly-o cheesecake jelly beans cake dessert. Tootsie roll tootsie roll bonbon pastry croissant gummi bears cake cake. Fruitcake sugar plum halvah gingerbread cookie pastry chupa chups wafer lemon drops. Marshmallow liquorice oat cake lollipop. Lemon drops oat cake halvah liquorice danish powder cupcake soufflé. Cake tart topping jelly-o tart sugar plum. Chocolate bar cookie wafer tootsie roll candy cotton candy toffee pie donut.</p> Wafer donut candy soufflé lemon drops icing. Marzipan gummi bears pie
<p>Ice cream lollipop marshmallow tiramisu jujubes croissant. Bear claw lemon drops marzipan candy bonbon cupcake powder. Candy canes cheesecake bear claw pastry cake donut jujubes. Icing tart jelly-o soufflé bonbon apple pie. Cheesecake pie chupa chups toffee powder. Bonbon lemon drops carrot cake pudding candy halvah cheesecake lollipop cupcake. Pudding marshmallow fruitcake. Gummi bears bonbon chupa chups lemon drops. Wafer dessert gummies gummi bears biscuit donut tiramisu gummi bears brownie. Tootsie roll liquorice bonbon cookie. Sesame snaps chocolate bar cake croissant chupa chups cheesecake gingerbread tiramisu jelly. Cheesecake ice cream muffin lollipop gummies. Sesame snaps jelly beans sweet bear claw tart.</p> danish lollipop pudding powder gummi bears sweet. Pie sweet roll sweet
<p>Sweet topping chupa chups chocolate cake jelly-o liquorice danish. Pastry jelly beans apple pie dessert pastry lemon drops marzipan gummies. Jelly beans macaroon bear claw cotton candy. Toffee sweet lollipop toffee oat cake. Jelly-o oat cake fruitcake chocolate bar sweet. Lemon drops gummies chocolate cake lollipop bear claw croissant danish icing. Chocolate bar donut brownie chocolate cake lemon drops chocolate bar. Cake fruitcake pudding chocolate apple pie. Brownie tiramisu chocolate macaroon lemon drops wafer soufflé jujubes icing. Cheesecake tiramisu cake macaroon tart lollipop donut. Gummi bears dragée pudding bear claw. Muffin cake cupcake candy canes. Soufflé candy canes biscuit. Macaroon gummies danish.</p> roll topping chocolate bar dragée pudding chocolate cake. Croissant sweet
<p>Cupcake cupcake tart. Cotton candy danish candy canes oat cake ice cream candy canes powder wafer. Chocolate sesame snaps oat cake dragée cheesecake. Sesame snaps marshmallow topping liquorice cookie marshmallow. Liquorice pudding chocolate bar. Cake powder brownie fruitcake. Carrot cake dessert marzipan sugar plum cupcake cheesecake pastry. Apple pie macaroon ice cream fruitcake apple pie cookie. Tootsie roll ice cream oat cake cheesecake donut cheesecake bear claw. Sesame snaps marzipan jelly beans chocolate tootsie roll. Chocolate bar donut dragée ice cream biscuit. Pie candy canes muffin candy canes ice cream tiramisu.</p> chocolate bar cheesecake candy canes. Tootsie roll icing macaroon bonbon
cupcake apple pie candy canes biscuit candy canes. Jujubes jelly liquorice
toffee gingerbread. Candy tootsie roll macaroon chocolate bar icing sugar
plum pie. Icing gummies chocolate bar chocolate marzipan bonbon cookie
chocolate tart. Caramels danish halvah croissant. Cheesecake cookie
tootsie roll ice cream. Powder dessert carrot cake muffin tiramisu lemon
drops liquorice topping brownie. Soufflé chocolate cake croissant cupcake
jelly.
</p>
<p>
Muffin gummies dessert cheesecake candy canes. Candy canes danish cotton
candy tart dessert powder bear claw marshmallow. Muffin chocolate
marshmallow danish. Chocolate bar biscuit cake tiramisu. Topping sweet
brownie jujubes powder marzipan. Croissant wafer bonbon chupa chups cake
cake marzipan caramels jujubes. Cupcake cheesecake sweet roll marshmallow
lollipop danish jujubes jelly icing. Apple pie chupa chups lollipop
jelly-o cheesecake jelly beans cake dessert. Tootsie roll tootsie roll
bonbon pastry croissant gummi bears cake cake. Fruitcake sugar plum halvah
gingerbread cookie pastry chupa chups wafer lemon drops. Marshmallow
liquorice oat cake lollipop. Lemon drops oat cake halvah liquorice danish
powder cupcake soufflé. Cake tart topping jelly-o tart sugar plum.
Chocolate bar cookie wafer tootsie roll candy cotton candy toffee pie
donut.
</p>
<p>
Ice cream lollipop marshmallow tiramisu jujubes croissant. Bear claw lemon
drops marzipan candy bonbon cupcake powder. Candy canes cheesecake bear
claw pastry cake donut jujubes. Icing tart jelly-o soufflé bonbon apple
pie. Cheesecake pie chupa chups toffee powder. Bonbon lemon drops carrot
cake pudding candy halvah cheesecake lollipop cupcake. Pudding marshmallow
fruitcake. Gummi bears bonbon chupa chups lemon drops. Wafer dessert
gummies gummi bears biscuit donut tiramisu gummi bears brownie. Tootsie
roll liquorice bonbon cookie. Sesame snaps chocolate bar cake croissant
chupa chups cheesecake gingerbread tiramisu jelly. Cheesecake ice cream
muffin lollipop gummies. Sesame snaps jelly beans sweet bear claw tart.
</p>
<p>
Sweet topping chupa chups chocolate cake jelly-o liquorice danish. Pastry
jelly beans apple pie dessert pastry lemon drops marzipan gummies. Jelly
beans macaroon bear claw cotton candy. Toffee sweet lollipop toffee oat
cake. Jelly-o oat cake fruitcake chocolate bar sweet. Lemon drops gummies
chocolate cake lollipop bear claw croissant danish icing. Chocolate bar
donut brownie chocolate cake lemon drops chocolate bar. Cake fruitcake
pudding chocolate apple pie. Brownie tiramisu chocolate macaroon lemon
drops wafer soufflé jujubes icing. Cheesecake tiramisu cake macaroon tart
lollipop donut. Gummi bears dragée pudding bear claw. Muffin cake cupcake
candy canes. Soufflé candy canes biscuit. Macaroon gummies danish.
</p>
<p>
Cupcake cupcake tart. Cotton candy danish candy canes oat cake ice cream
candy canes powder wafer. Chocolate sesame snaps oat cake dragée
cheesecake. Sesame snaps marshmallow topping liquorice cookie marshmallow.
Liquorice pudding chocolate bar. Cake powder brownie fruitcake. Carrot
cake dessert marzipan sugar plum cupcake cheesecake pastry. Apple pie
macaroon ice cream fruitcake apple pie cookie. Tootsie roll ice cream oat
cake cheesecake donut cheesecake bear claw. Sesame snaps marzipan jelly
beans chocolate tootsie roll. Chocolate bar donut dragée ice cream
biscuit. Pie candy canes muffin candy canes ice cream tiramisu.
</p>
</div> </div>
) )
This diff is collapsed.
...@@ -6,21 +6,17 @@ const path = require('path') ...@@ -6,21 +6,17 @@ const path = require('path')
// Where your antd-custom.less file lives // Where your antd-custom.less file lives
const themeVariables = lessToJS( const themeVariables = lessToJS(
fs.readFileSync( fs.readFileSync(path.resolve(__dirname, './assets/antd-custom.less'), 'utf8')
path.resolve(__dirname, './assets/antd-custom.less'),
'utf8'
)
) )
// fix: prevents error when .less files are required by node // fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') { if (typeof require !== 'undefined') {
require.extensions['.less'] = (file) => {} require.extensions['.less'] = file => {}
} }
module.exports = withLess({ module.exports = withLess({
lessLoaderOptions: { lessLoaderOptions: {
javascriptEnabled: true, javascriptEnabled: true,
modifyVars: themeVariables // make your antd custom effective modifyVars: themeVariables // make your antd custom effective
}, }
}) })
import { Form, Select, InputNumber, DatePicker, Switch, Slider, Button } from 'antd' import {
Form,
Select,
InputNumber,
DatePicker,
Switch,
Slider,
Button
} from 'antd'
const FormItem = Form.Item const FormItem = Form.Item
const Option = Select.Option const Option = Select.Option
...@@ -11,35 +19,37 @@ export default () => ( ...@@ -11,35 +19,37 @@ export default () => (
labelCol={{ span: 8 }} labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }} wrapperCol={{ span: 8 }}
> >
<InputNumber size='large' min={1} max={10} style={{ width: 100 }} defaultValue={3} name='inputNumber' /> <InputNumber
size='large'
min={1}
max={10}
style={{ width: 100 }}
defaultValue={3}
name='inputNumber'
/>
<a href='#'>Link</a> <a href='#'>Link</a>
</FormItem> </FormItem>
<FormItem <FormItem label='Switch' labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}>
label='Switch'
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Switch defaultChecked name='switch' /> <Switch defaultChecked name='switch' />
</FormItem> </FormItem>
<FormItem <FormItem label='Slider' labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}>
label='Slider'
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Slider defaultValue={70} /> <Slider defaultValue={70} />
</FormItem> </FormItem>
<FormItem <FormItem label='Select' labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}>
label='Select' <Select
labelCol={{ span: 8 }} size='large'
wrapperCol={{ span: 8 }} defaultValue='lucy'
style={{ width: 192 }}
name='select'
> >
<Select size='large' defaultValue='lucy' style={{ width: 192 }} name='select'>
<Option value='jack'>jack</Option> <Option value='jack'>jack</Option>
<Option value='lucy'>lucy</Option> <Option value='lucy'>lucy</Option>
<Option value='disabled' disabled>disabled</Option> <Option value='disabled' disabled>
disabled
</Option>
<Option value='yiminghe'>yiminghe</Option> <Option value='yiminghe'>yiminghe</Option>
</Select> </Select>
</FormItem> </FormItem>
...@@ -51,10 +61,7 @@ export default () => ( ...@@ -51,10 +61,7 @@ export default () => (
> >
<DatePicker name='startDate' /> <DatePicker name='startDate' />
</FormItem> </FormItem>
<FormItem <FormItem style={{ marginTop: 48 }} wrapperCol={{ span: 8, offset: 8 }}>
style={{ marginTop: 48 }}
wrapperCol={{ span: 8, offset: 8 }}
>
<Button size='large' type='primary' htmlType='submit'> <Button size='large' type='primary' htmlType='submit'>
OK OK
</Button> </Button>
......
...@@ -3,7 +3,7 @@ const withCss = require('@zeit/next-css') ...@@ -3,7 +3,7 @@ const withCss = require('@zeit/next-css')
// fix: prevents error when .css files are required by node // fix: prevents error when .css files are required by node
if (typeof require !== 'undefined') { if (typeof require !== 'undefined') {
require.extensions['.css'] = (file) => {} require.extensions['.css'] = file => {}
} }
module.exports = withCss() module.exports = withCss()
import { Form, Select, InputNumber, DatePicker, Switch, Slider, Button } from 'antd' import {
Form,
Select,
InputNumber,
DatePicker,
Switch,
Slider,
Button
} from 'antd'
const FormItem = Form.Item const FormItem = Form.Item
const Option = Select.Option const Option = Select.Option
...@@ -11,35 +19,37 @@ export default () => ( ...@@ -11,35 +19,37 @@ export default () => (
labelCol={{ span: 8 }} labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }} wrapperCol={{ span: 8 }}
> >
<InputNumber size='large' min={1} max={10} style={{ width: 100 }} defaultValue={3} name='inputNumber' /> <InputNumber
size='large'
min={1}
max={10}
style={{ width: 100 }}
defaultValue={3}
name='inputNumber'
/>
<a href='#'>Link</a> <a href='#'>Link</a>
</FormItem> </FormItem>
<FormItem <FormItem label='Switch' labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}>
label='Switch'
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Switch defaultChecked name='switch' /> <Switch defaultChecked name='switch' />
</FormItem> </FormItem>
<FormItem <FormItem label='Slider' labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}>
label='Slider'
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Slider defaultValue={70} /> <Slider defaultValue={70} />
</FormItem> </FormItem>
<FormItem <FormItem label='Select' labelCol={{ span: 8 }} wrapperCol={{ span: 8 }}>
label='Select' <Select
labelCol={{ span: 8 }} size='large'
wrapperCol={{ span: 8 }} defaultValue='lucy'
style={{ width: 192 }}
name='select'
> >
<Select size='large' defaultValue='lucy' style={{ width: 192 }} name='select'>
<Option value='jack'>jack</Option> <Option value='jack'>jack</Option>
<Option value='lucy'>lucy</Option> <Option value='lucy'>lucy</Option>
<Option value='disabled' disabled>disabled</Option> <Option value='disabled' disabled>
disabled
</Option>
<Option value='yiminghe'>yiminghe</Option> <Option value='yiminghe'>yiminghe</Option>
</Select> </Select>
</FormItem> </FormItem>
...@@ -51,10 +61,7 @@ export default () => ( ...@@ -51,10 +61,7 @@ export default () => (
> >
<DatePicker name='startDate' /> <DatePicker name='startDate' />
</FormItem> </FormItem>
<FormItem <FormItem style={{ marginTop: 48 }} wrapperCol={{ span: 8, offset: 8 }}>
style={{ marginTop: 48 }}
wrapperCol={{ span: 8, offset: 8 }}
>
<Button size='large' type='primary' htmlType='submit'> <Button size='large' type='primary' htmlType='submit'>
OK OK
</Button> </Button>
......
...@@ -26,8 +26,6 @@ export default withRouter(({ router, children, title }) => ( ...@@ -26,8 +26,6 @@ export default withRouter(({ router, children, title }) => (
position: relative; position: relative;
} }
`}</style> `}</style>
<WingBlank> <WingBlank>{children}</WingBlank>
{children}
</WingBlank>
</div> </div>
)) ))
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment