Skip to content

Commit 027309b

Browse files
authored
Merge pull request #401 from netlify/demo-site
feat: add demo site
2 parents 9cb6e2b + 2b60d75 commit 027309b

34 files changed

+1151
-1
lines changed

.netlify/state.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"siteId": "b7ec5732-32dc-4d00-9108-051d100b6d2e"
3+
}

demo/.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+
36+
netlify/functions
37+
.netlify/functions
38+
.netlify/cache

demo/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
```
12+
13+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14+
15+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
16+
17+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
18+
19+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
20+
21+
## Learn More
22+
23+
To learn more about Next.js, take a look at the following resources:
24+
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29+
30+
## Deploy on Vercel
31+
32+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33+
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

demo/components/Header.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Header() {
2+
return <h1>header</h1>
3+
}

demo/netlify.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[build]
2+
command = "npm run build"
3+
publish = "out/"
4+
# Build for updates outside of the site
5+
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF .."
6+
7+
[[plugins]]
8+
package = ".."
9+
10+
[[plugins]]
11+
package = "@netlify/plugin-local-install-core"

demo/next.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
module.exports = {
3+
target: 'serverless'
4+
}
5+

demo/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "demo",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start"
9+
},
10+
"dependencies": {
11+
"next": "10.2.3",
12+
"react": "17.0.2",
13+
"react-dom": "17.0.2"
14+
}
15+
}

demo/pages/_app.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import '../styles/globals.css'
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp

demo/pages/api/hello-background.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default (req, res) => {
2+
res.setHeader('Content-Type', 'application/json')
3+
res.status(200)
4+
res.json({ message: 'hello world :)' })
5+
}

demo/pages/api/hello.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
3+
export default (req, res) => {
4+
res.status(200).json({ name: 'John Doe' })
5+
}

demo/pages/api/shows/[...params].js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export default async (req, res) => {
2+
// Respond with JSON
3+
res.setHeader('Content-Type', 'application/json')
4+
5+
// Get the params and query string parameters
6+
const { query } = req
7+
const { params, ...queryStringParams } = query
8+
9+
// Get the ID of the show
10+
const id = params[0]
11+
12+
// Get the data
13+
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`)
14+
const data = await fetchRes.json()
15+
16+
// If show was found, return it
17+
if (fetchRes.status == 200) {
18+
res.status(200)
19+
res.json({ params, queryStringParams, show: data })
20+
}
21+
// If show was not found, return error
22+
else {
23+
res.status(404)
24+
res.json({ error: 'Show not found' })
25+
}
26+
}

demo/pages/api/shows/[id].js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default async (req, res) => {
2+
// Respond with JSON
3+
res.setHeader('Content-Type', 'application/json')
4+
5+
// Get the ID of the show
6+
const { query } = req
7+
const { id } = query
8+
9+
// Get the data
10+
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`)
11+
const data = await fetchRes.json()
12+
13+
// If show was found, return it
14+
if (fetchRes.status == 200) {
15+
res.status(200)
16+
res.json({ show: data })
17+
}
18+
// If show was not found, return error
19+
else {
20+
res.status(404)
21+
res.json({ error: 'Show not found' })
22+
}
23+
}

demo/pages/deep/import.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Link from 'next/link'
2+
import dynamic from 'next/dynamic'
3+
const Header = dynamic(() => import(/* webpackChunkName: 'header' */ '../../components/Header'), { ssr: true })
4+
5+
const Show = ({ show }) => (
6+
<div>
7+
<Header />
8+
<p>
9+
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
10+
<br />
11+
Refresh the page to see server-side rendering in action.
12+
<br />
13+
You can also try changing the ID to any other number between 1-10000.
14+
</p>
15+
16+
<hr />
17+
18+
<h1>Show #{show.id}</h1>
19+
<p>{show.name}</p>
20+
21+
<hr />
22+
23+
<Link href="/">
24+
<a>Go back home</a>
25+
</Link>
26+
</div>
27+
)
28+
29+
export const getServerSideProps = async ({ params }) => {
30+
const res = await fetch('https://api.tvmaze.com/shows/42')
31+
const data = await res.json()
32+
33+
return {
34+
props: {
35+
show: data,
36+
},
37+
}
38+
}
39+
40+
export default Show

demo/pages/getServerSideProps/[id].js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Error from 'next/error'
2+
import Link from 'next/link'
3+
4+
const Show = ({ errorCode, show }) => {
5+
// If show item was not found, render 404 page
6+
if (errorCode) {
7+
return <Error statusCode={errorCode} />
8+
}
9+
10+
// Otherwise, render show
11+
return (
12+
<div>
13+
<p>
14+
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
15+
<br />
16+
Refresh the page to see server-side rendering in action.
17+
<br />
18+
You can also try changing the ID to any other number between 1-10000.
19+
</p>
20+
21+
<hr />
22+
23+
<h1>Show #{show.id}</h1>
24+
<p>{show.name}</p>
25+
26+
<hr />
27+
28+
<Link href="/">
29+
<a>Go back home</a>
30+
</Link>
31+
</div>
32+
)
33+
}
34+
35+
export const getServerSideProps = async ({ params }) => {
36+
// The ID to render
37+
const { id } = params
38+
39+
const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
40+
const data = await res.json()
41+
42+
// Set error code if show item could not be found
43+
const errorCode = res.status > 200 ? res.status : false
44+
45+
return {
46+
props: {
47+
errorCode,
48+
show: data,
49+
},
50+
}
51+
}
52+
53+
export default Show
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Error from 'next/error'
2+
import Link from 'next/link'
3+
4+
const Show = ({ errorCode, show }) => {
5+
// If show item was not found, render 404 page
6+
if (errorCode) {
7+
return <Error statusCode={errorCode} />
8+
}
9+
10+
// Otherwise, render show
11+
return (
12+
<div>
13+
<p>
14+
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
15+
<br />
16+
Refresh the page to see server-side rendering in action.
17+
<br />
18+
You can also try changing the ID to any other number between 1-10000.
19+
</p>
20+
21+
<hr />
22+
23+
<h1>Show #{show.id}</h1>
24+
<p>{show.name}</p>
25+
26+
<hr />
27+
28+
<Link href="/">
29+
<a>Go back home</a>
30+
</Link>
31+
</div>
32+
)
33+
}
34+
35+
export const getServerSideProps = async ({ params }) => {
36+
// The ID to render
37+
const { slug } = params
38+
39+
const res = await fetch(`https://api.tvmaze.com/shows/${slug[0]}`)
40+
const data = await res.json()
41+
42+
// Set error code if show item could not be found
43+
const errorCode = res.status > 200 ? res.status : false
44+
45+
return {
46+
props: {
47+
errorCode,
48+
show: data,
49+
},
50+
}
51+
}
52+
53+
export default Show
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Link from 'next/link'
2+
3+
const Show = ({ show }) => (
4+
<div>
5+
<p>
6+
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
7+
<br />
8+
Refresh the page to see server-side rendering in action.
9+
<br />
10+
You can also try changing the ID to any other number between 1-10000.
11+
</p>
12+
13+
<hr />
14+
15+
<h1>Show #{show.id}</h1>
16+
<p>{show.name}</p>
17+
18+
<hr />
19+
20+
<Link href="/">
21+
<a>Go back home</a>
22+
</Link>
23+
</div>
24+
)
25+
26+
export const getServerSideProps = async ({ params }) => {
27+
const res = await fetch('https://api.tvmaze.com/shows/42')
28+
const data = await res.json()
29+
30+
return {
31+
props: {
32+
show: data,
33+
},
34+
}
35+
}
36+
37+
export default Show

0 commit comments

Comments
 (0)