Skip to content

Commit 686dd4c

Browse files
committed
Merge master into dynamic-import.
2 parents 753113b + a903503 commit 686dd4c

File tree

76 files changed

+1978
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1978
-1230
lines changed

examples/basic-css/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/basic-css)
12

23
# Basic CSS example
34

examples/custom-server-express/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/custom-server-express)
12

23
# Custom Express Server example
34

examples/custom-server-hapi/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/custom-server-hapi)
12

23
# Custom server using Hapi example
34

examples/custom-server-koa/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/custom-server-koa)
12

23
# Custom Koa Server example
34

examples/custom-server/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/custom-server)
12

23
# Custom server example
34

examples/data-fetch/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/data-fetch)
12

23
# Data fetch example
34

examples/head-elements/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/head-elements)
12

23
# Head elements example
34

examples/hello-world/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/hello-world)
12

23
# Hello World example
34

examples/layout-component/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/layout-component)
12

23
# Layout component example
34

examples/nested-components/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/nested-components)
12

23
# Example app using nested components
34

examples/parameterized-routing/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/parameterized-routing)
12

23
# Parametrized routes example (dynamic routing)
34

examples/progressive-render/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/progressive-render)
12
# Example app implementing progressive server-side render
23

34
## How to use

examples/shared-modules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/shared-modules)
12
# Example app using shared modules
23

34
## How to use

examples/ssr-caching/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/ssr-caching)
12

23
# Example app where it caches SSR'ed pages in the memory
34

examples/svg-components/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/svg-components)
12

23
# SVG components example
34

examples/using-inferno/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/using-inferno)
12

23
# Hello World example
34

examples/using-preact/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/using-preact)
12

23
# Hello World example
34

examples/using-router/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/using-router)
12
# Example app utilizing next/router for routing
23

34
## How to use

examples/with-amp/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-amp)
12

23
# Google AMP
34

examples/with-amp/pages/_document.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import Document, { Head } from 'next/document'
22
import { DOMProperty } from 'react-dom/lib/ReactInjection'
3+
import { properties as DOMProperties } from 'react-dom/lib/DOMProperty'
34

45
// By default React limit the set of valid DOM elements and attributes
56
// (https://github.com/facebook/react/issues/140) this config whitelist
67
// Amp elements/attributes
7-
DOMProperty.injectDOMPropertyConfig({
8-
Properties: { amp: DOMProperty.MUST_USE_ATTRIBUTE },
9-
isCustomAttribute: attributeName => attributeName.startsWith('amp-')
10-
})
8+
if (typeof DOMProperties.amp === 'undefined') {
9+
DOMProperty.injectDOMPropertyConfig({
10+
Properties: { amp: DOMProperty.MUST_USE_ATTRIBUTE },
11+
isCustomAttribute: attributeName => attributeName.startsWith('amp-')
12+
})
13+
}
1114

1215
export default class MyDocument extends Document {
1316
render () {

examples/with-aphrodite/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-aphrodite)
12

23
# Example app with aphrodite
34

examples/with-apollo-and-redux/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-apollo-and-redux)
12
# Apollo & Redux Example
23

34
## How to use

examples/with-apollo/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-apollo)
12
# Apollo Example
23

34
## Demo

examples/with-custom-babel-config/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-custom-babel-config)
12
# Example app using custom babel config
23

34
Download the example [or clone the repo](https://github.com/zeit/next.js):

examples/with-cxs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-cxs)
12

23
# Example app with cxs
34

examples/with-external-scoped-css/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-external-scoped-css)
12
## Scoped Style with external CSS file
23
The motivation for this example is using scoped css from external files and in the end generate a compiled static `.css` file to use in production..
34

examples/with-fela/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-fela)
12

23
# Example app with Fela
34

examples/with-fela/pages/_document.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export default class MyDocument extends Document {
2020
<html>
2121
<Head>
2222
<title>My page</title>
23-
<style id='fela-stylesheet'>{this.props.css}</style>
23+
<style
24+
dangerouslySetInnerHTML={{ __html: this.props.css }}
25+
id='fela-stylesheet'
26+
/>
2427
</Head>
2528
<body>
2629
<Main />

examples/with-fela/pages/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createComponent } from 'react-fela'
22
import Page from '../layout'
33

44
const title = ({ size }) => ({
5+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
56
fontSize: size + 'px',
67
color: 'red'
78
})

examples/with-firebase/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-firebase)
2+
3+
# With Firebase example
4+
5+
## How to use
6+
7+
Download the example [or clone the repo](https://github.com/zeit/next.js):
8+
9+
```bash
10+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-firebase
11+
cd with-firebase
12+
```
13+
14+
Set up firebase:
15+
- create a project
16+
- get your service account credentials and client credentials and set both in firebaseCredentials.js
17+
- set your firebase database url in server.js
18+
- on the firebase Authentication console, select Google as your provider
19+
20+
Install it and run:
21+
22+
```bash
23+
npm install
24+
npm run dev
25+
```
26+
27+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
28+
29+
```bash
30+
now
31+
```
32+
33+
## The idea behind the example
34+
The goal is to authenticate users with firebase and store their auth token in sessions. A logged in user will see their messages on page load and then be able to post new messages.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
clientCredentials: {
3+
// TODO firebase client config
4+
},
5+
serverCredentials: {
6+
// TODO service account json here
7+
}
8+
}

examples/with-firebase/package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"scripts": {
3+
"dev": "node server.js",
4+
"build": "next build",
5+
"start": "NODE_ENV=production node server.js"
6+
},
7+
"dependencies": {
8+
"body-parser": "^1.17.1",
9+
"express": "^4.14.0",
10+
"express-session": "^1.15.2",
11+
"firebase": "^3.7.5",
12+
"firebase-admin": "^4.2.0",
13+
"isomorphic-fetch": "2.2.1",
14+
"next": "latest",
15+
"react": "^15.4.2",
16+
"react-dom": "^15.4.2",
17+
"session-file-store": "^1.0.0"
18+
}
19+
}

examples/with-firebase/pages/index.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import React, { Component } from 'react'
2+
import firebase from 'firebase'
3+
import 'isomorphic-fetch'
4+
import { clientCredentials } from '../firebaseCredentials'
5+
6+
export default class Index extends Component {
7+
static async getInitialProps ({req, query}) {
8+
const user = req && req.session ? req.session.decodedToken : null
9+
const snap = await req.firebaseServer.database().ref('messages').once('value')
10+
return { user, messages: snap.val() }
11+
}
12+
13+
constructor (props) {
14+
super(props)
15+
this.state = {
16+
user: this.props.user,
17+
value: '',
18+
messages: this.props.messages
19+
}
20+
21+
this.addDbListener = this.addDbListener.bind(this)
22+
this.handleChange = this.handleChange.bind(this)
23+
this.handleSubmit = this.handleSubmit.bind(this)
24+
}
25+
26+
componentDidMount () {
27+
firebase.initializeApp(clientCredentials)
28+
29+
if (this.state.user) this.addDbListener()
30+
31+
firebase.auth().onAuthStateChanged(user => {
32+
if (user) {
33+
this.setState({ user: user })
34+
return user.getToken()
35+
.then((token) => {
36+
// eslint-disable-next-line no-undef
37+
return fetch('/api/login', {
38+
method: 'POST',
39+
// eslint-disable-next-line no-undef
40+
headers: new Headers({ 'Content-Type': 'application/json' }),
41+
credentials: 'same-origin',
42+
body: JSON.stringify({ token })
43+
})
44+
}).then((res) => this.addDbListener())
45+
} else {
46+
this.setState({ user: null })
47+
// eslint-disable-next-line no-undef
48+
fetch('/api/logout', {
49+
method: 'POST',
50+
credentials: 'same-origin'
51+
}).then(() => firebase.database().ref('messages').off())
52+
}
53+
})
54+
}
55+
56+
addDbListener () {
57+
firebase.database().ref('messages').on('value', snap => {
58+
const messages = snap.val()
59+
if (messages) this.setState({ messages })
60+
})
61+
}
62+
63+
handleChange (event) {
64+
this.setState({ value: event.target.value })
65+
}
66+
67+
handleSubmit (event) {
68+
event.preventDefault()
69+
const date = new Date().getTime()
70+
firebase.database().ref(`messages/${date}`).set({
71+
id: date,
72+
text: this.state.value
73+
})
74+
this.setState({ value: '' })
75+
}
76+
77+
handleLogin () {
78+
firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())
79+
}
80+
81+
handleLogout () {
82+
firebase.auth().signOut()
83+
}
84+
85+
render () {
86+
const { user, value, messages } = this.state
87+
88+
return <div>
89+
{
90+
user
91+
? <button onClick={this.handleLogout}>Logout</button>
92+
: <button onClick={this.handleLogin}>Login</button>
93+
}
94+
{
95+
user &&
96+
<div>
97+
<form onSubmit={this.handleSubmit}>
98+
<input
99+
type={'text'}
100+
onChange={this.handleChange}
101+
placeholder={'add message'}
102+
value={value}
103+
/>
104+
</form>
105+
<ul>
106+
{
107+
messages &&
108+
Object.keys(messages).map(key => <li key={key}>{messages[key].text}</li>)
109+
}
110+
</ul>
111+
</div>
112+
}
113+
</div>
114+
}
115+
}

0 commit comments

Comments
 (0)