Skip to content

feat: add demo site #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .netlify/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"siteId": "b7ec5732-32dc-4d00-9108-051d100b6d2e"
}
38 changes: 38 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel

netlify/functions
.netlify/functions
.netlify/cache
34 changes: 34 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[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`.

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.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

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.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
3 changes: 3 additions & 0 deletions demo/components/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Header() {
return <h1>header</h1>
}
11 changes: 11 additions & 0 deletions demo/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[build]
command = "npm run build"
publish = "out/"
# Build for updates outside of the site
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF .."

[[plugins]]
package = ".."

[[plugins]]
package = "@netlify/plugin-local-install-core"
5 changes: 5 additions & 0 deletions demo/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

module.exports = {
target: 'serverless'
}

15 changes: 15 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "demo",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "10.2.3",
"react": "17.0.2",
"react-dom": "17.0.2"
}
}
7 changes: 7 additions & 0 deletions demo/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
5 changes: 5 additions & 0 deletions demo/pages/api/hello-background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default (req, res) => {
res.setHeader('Content-Type', 'application/json')
res.status(200)
res.json({ message: 'hello world :)' })
}
5 changes: 5 additions & 0 deletions demo/pages/api/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

export default (req, res) => {
res.status(200).json({ name: 'John Doe' })
}
26 changes: 26 additions & 0 deletions demo/pages/api/shows/[...params].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default async (req, res) => {
// Respond with JSON
res.setHeader('Content-Type', 'application/json')

// Get the params and query string parameters
const { query } = req
const { params, ...queryStringParams } = query

// Get the ID of the show
const id = params[0]

// Get the data
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`)
const data = await fetchRes.json()

// If show was found, return it
if (fetchRes.status == 200) {
res.status(200)
res.json({ params, queryStringParams, show: data })
}
// If show was not found, return error
else {
res.status(404)
res.json({ error: 'Show not found' })
}
}
23 changes: 23 additions & 0 deletions demo/pages/api/shows/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default async (req, res) => {
// Respond with JSON
res.setHeader('Content-Type', 'application/json')

// Get the ID of the show
const { query } = req
const { id } = query

// Get the data
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`)
const data = await fetchRes.json()

// If show was found, return it
if (fetchRes.status == 200) {
res.status(200)
res.json({ show: data })
}
// If show was not found, return error
else {
res.status(404)
res.json({ error: 'Show not found' })
}
}
40 changes: 40 additions & 0 deletions demo/pages/deep/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Link from 'next/link'
import dynamic from 'next/dynamic'
const Header = dynamic(() => import(/* webpackChunkName: 'header' */ '../../components/Header'), { ssr: true })

const Show = ({ show }) => (
<div>
<Header />
<p>
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
<br />
Refresh the page to see server-side rendering in action.
<br />
You can also try changing the ID to any other number between 1-10000.
</p>

<hr />

<h1>Show #{show.id}</h1>
<p>{show.name}</p>

<hr />

<Link href="/">
<a>Go back home</a>
</Link>
</div>
)

export const getServerSideProps = async ({ params }) => {
const res = await fetch('https://api.tvmaze.com/shows/42')
const data = await res.json()

return {
props: {
show: data,
},
}
}

export default Show
53 changes: 53 additions & 0 deletions demo/pages/getServerSideProps/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Error from 'next/error'
import Link from 'next/link'

const Show = ({ errorCode, show }) => {
// If show item was not found, render 404 page
if (errorCode) {
return <Error statusCode={errorCode} />
}

// Otherwise, render show
return (
<div>
<p>
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
<br />
Refresh the page to see server-side rendering in action.
<br />
You can also try changing the ID to any other number between 1-10000.
</p>

<hr />

<h1>Show #{show.id}</h1>
<p>{show.name}</p>

<hr />

<Link href="/">
<a>Go back home</a>
</Link>
</div>
)
}

export const getServerSideProps = async ({ params }) => {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const data = await res.json()

// Set error code if show item could not be found
const errorCode = res.status > 200 ? res.status : false

return {
props: {
errorCode,
show: data,
},
}
}

export default Show
53 changes: 53 additions & 0 deletions demo/pages/getServerSideProps/all/[[...slug]].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Error from 'next/error'
import Link from 'next/link'

const Show = ({ errorCode, show }) => {
// If show item was not found, render 404 page
if (errorCode) {
return <Error statusCode={errorCode} />
}

// Otherwise, render show
return (
<div>
<p>
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
<br />
Refresh the page to see server-side rendering in action.
<br />
You can also try changing the ID to any other number between 1-10000.
</p>

<hr />

<h1>Show #{show.id}</h1>
<p>{show.name}</p>

<hr />

<Link href="/">
<a>Go back home</a>
</Link>
</div>
)
}

export const getServerSideProps = async ({ params }) => {
// The ID to render
const { slug } = params

const res = await fetch(`https://api.tvmaze.com/shows/${slug[0]}`)
const data = await res.json()

// Set error code if show item could not be found
const errorCode = res.status > 200 ? res.status : false

return {
props: {
errorCode,
show: data,
},
}
}

export default Show
37 changes: 37 additions & 0 deletions demo/pages/getServerSideProps/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Link from 'next/link'

const Show = ({ show }) => (
<div>
<p>
This page uses getInitialProps() to fetch the show with the ID provided in the URL: /shows/:id
<br />
Refresh the page to see server-side rendering in action.
<br />
You can also try changing the ID to any other number between 1-10000.
</p>

<hr />

<h1>Show #{show.id}</h1>
<p>{show.name}</p>

<hr />

<Link href="/">
<a>Go back home</a>
</Link>
</div>
)

export const getServerSideProps = async ({ params }) => {
const res = await fetch('https://api.tvmaze.com/shows/42')
const data = await res.json()

return {
props: {
show: data,
},
}
}

export default Show
Loading