Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 98c2721

Browse files
committed
Set up prettier for automatic code formatting
Make our code look beautiful and consistent :)
1 parent 131de77 commit 98c2721

File tree

85 files changed

+2187
-1963
lines changed

Some content is hidden

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

85 files changed

+2187
-1963
lines changed

.prettierignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Test builds
2+
cypress/builds/
3+
tests/builds/
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
15+
# Directory for instrumented libs generated by jscoverage/JSCover
16+
lib-cov
17+
18+
# Coverage directory used by tools like istanbul
19+
coverage
20+
21+
# nyc test coverage
22+
.nyc_output
23+
24+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
25+
.grunt
26+
27+
# node-waf configuration
28+
.lock-wscript
29+
30+
# Compiled binary addons (http://nodejs.org/api/addons.html)
31+
build/Release
32+
33+
# Dependency directories
34+
node_modules
35+
jspm_packages
36+
37+
# Optional npm cache directory
38+
.npm
39+
40+
# Optional REPL history
41+
.node_repl_history
42+
.next

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
## 2.0.0 (2020-06-02)
3131

3232
- **Breaking: You must change your `netlify.toml` configuration for next-on-netlify v2.0.0.** Please [look at the README](https://github.com/netlify/next-on-netlify#3-configure-netlify) for the latest configuration.
33-
`next-on-netlify` now builds pre-rendered pages and static assets in `out_publish`. Netlify Functions for SSR pages are built to `out_functions`.
33+
`next-on-netlify` now builds pre-rendered pages and static assets in `out_publish`. Netlify Functions for SSR pages are built to `out_functions`.
3434
- Add support for `getStaticProps` ([#7](https://github.com/netlify/next-on-netlify/issues/7))
3535
- Add support for `getStaticPaths` with and without fallback ([#7](https://github.com/netlify/next-on-netlify/issues/7))
3636
- Add support for `getServerSideProps` ([#7](https://github.com/netlify/next-on-netlify/issues/7))
3737
- Query string parameters are now correctly passed to Next Pages and API endpoints ([#9](https://github.com/netlify/next-on-netlify/issues/9))
3838
- Response headers are now correctly set ([#9](https://github.com/netlify/next-on-netlify/issues/9#issuecomment-633288179))
3939
- When a user encounters a 404, `next-on-netlify` now display the NextJS 404 page rather than Netlify's default 404 page. You can [customize the NextJS 404 page](https://nextjs.org/docs/advanced-features/custom-error-page#customizing-the-404-page).
40-
([#2](https://github.com/netlify/next-on-netlify/issues/2))
40+
([#2](https://github.com/netlify/next-on-netlify/issues/2))
4141
- Every page with server-side rendering is now converted to a stand-alone Netlify Function. Previously, all SSR pages were bundled in a single Netlify Function.
4242
- `next-on-netlify` now prints out which pages are being converted to Netlify Functions for SSR, which pages are served as pre-rendered HTML, and the redirects that are being generated.
4343
- Adding custom redirects via a `_redirects` file in the project root is no longer supported. Let me know if you want this back. Or define your redirects in `netlify.toml`.

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@ Principal Developer Experience Engineer at Netlify, will be joining
2121

2222
next-on-netlify is a utility for hosting NextJS applications with Server-Side Rendering on Netlify. It wraps your NextJS application in a tiny compatibility layer, so that pages can be server-side rendered with Netlify functions.
2323

24-
- Demo: https://next-on.netlify.com/
24+
- Demo: https://next-on.netlify.com/
2525
- Example repository: https://github.com/FinnWoelm/next-on-netlify-demo
2626

2727
## Table of Contents
28-
* [Installation](#installation)
29-
* [Setup](#setup)
30-
- [1. Set NextJS target to serverless](#1-set-nextjs--target-to-serverless)
28+
29+
- [Installation](#installation)
30+
- [Setup](#setup)
31+
- [1. Set NextJS target to serverless](#1-set-nextjs--target-to-serverless)
3132
- [2. Add postbuild hook](#2-add-postbuild-hook)
3233
- [3. Configure Netlify](#3-configure-netlify)
33-
* [Optional Extras](#optional-extras)
34+
- [Optional Extras](#optional-extras)
3435
- [Preview Locally](#preview-locally)
3536
- [Custom Netlify Redirects](#custom-netlify-redirects)
3637
- [Custom Netlify Functions](#custom-netlify-functions)
37-
* [Caveats](#caveats)
38-
+ [Preview Mode](#preview-mode)
39-
+ [Fallbacks for Pages with `getStaticPaths`](#fallbacks-for-pages-with-getstaticpaths)
40-
* [Showcase](#showcase)
41-
* [Credits](#credits)
38+
- [Caveats](#caveats)
39+
- [Preview Mode](#preview-mode)
40+
- [Fallbacks for Pages with `getStaticPaths`](#fallbacks-for-pages-with-getstaticpaths)
41+
- [Showcase](#showcase)
42+
- [Credits](#credits)
4243

4344
## Installation
4445

@@ -48,7 +49,7 @@ npm install --save next-on-netlify
4849

4950
## Setup
5051

51-
#### 1. Set NextJS target to serverless
52+
#### 1. Set NextJS target to serverless
5253

5354
We must build our NextJS app as a serverless app. You can read more about serverless NextJS [here](https://nextjs.org/docs/api-reference/next.config.js/build-target#serverless-target).
5455

@@ -59,13 +60,13 @@ It's super simple. Just create a `next.config.js` file and write the following:
5960

6061
module.exports = {
6162
// Target must be serverless
62-
target: 'serverless'
63+
target: "serverless",
6364
};
6465
```
6566

6667
#### 2. Add postbuild hook
6768

68-
The next-on-netlify package adds the `next-on-netlify` command. When we run this command, some magic happens to prepare our NextJS app for hosting on Netlify*.
69+
The next-on-netlify package adds the `next-on-netlify` command. When we run this command, some magic happens to prepare our NextJS app for hosting on Netlify\*.
6970

7071
We want the next-on-netlify command to run after we build our NextJS application. So let's add a postbuild hook to our package.json file:
7172

@@ -140,6 +141,7 @@ Lastly, add the following lines to your `.gitignore`:
140141
Now you're all set.
141142

142143
From now on, whenever you want to preview your application locally, just run:
144+
143145
1. `npm run build`: This will run `next build` to build your NextJS app and `next-on-netlify` to prepare your NextJS app for compatibility with Netlify
144146
1. `netlify dev`: This will emulate Netlify on your computer and let you preview your app on `http://localhost:8888`.
145147

@@ -152,7 +154,7 @@ The precedence of these rules are:
152154
- `next-on-netlify` redirects
153155
- `netlify.toml`
154156

155-
[Read more about Netlify redirects here](https://docs.netlify.com/routing/redirects/).
157+
[Read more about Netlify redirects here](https://docs.netlify.com/routing/redirects/).
156158

157159
#### Custom Netlify Functions
158160

@@ -165,7 +167,6 @@ SSR pages and API endpoints. It is currently not possible to create custom Netli
165167

166168
[NextJS Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode) does not work on pages that are pre-rendered (pages with `getStaticProps`). Netlify currently does not support cookie-based redirects, which are needed for supporting preview mode on pre-rendered pages. Preview mode works correctly on any server-side-rendered pages (pages with `getInitialProps` or `getServerSideProps`). See: [Issue #10](https://github.com/netlify/next-on-netlify/issues/10)
167169

168-
169170
### Fallbacks for Pages with `getStaticPaths`
170171

171172
[Fallback pages](https://nextjs.org/docs/basic-features/data-fetching#fallback-true) behave differently with `next-on-netlify` than they do with NextJS. On NextJS, when navigating to a path that is not defined in `getStaticPaths`, it first displays the fallback page. NextJS then generates the HTML in the background and caches it for future requests.
@@ -188,6 +189,7 @@ Are you building something awesome with `next-on-netlify`? 🔥 Let me know and
188189
📣 Shoutout to [@mottox2](https://github.com/mottox2) (a pioneer of hosting NextJS on Netlify) and [@danielcondemarin](https://github.com/danielcondemarin) (author of serverless-next.js for AWS). The two were big inspirations for this package.
189190

190191
🙌 Big "thank you" to the following people for their contributions, support, and beta testing:
192+
191193
- [@spencewood](https://github.com/spencewood)
192194
- [@alxhghs](https://github.com/alxhghs)
193195
- [@gamliela](https://github.com/gamliela)

cypress/fixtures/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
target: 'serverless',
2+
target: "serverless",
33
};
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,46 @@
1-
import { useRouter } from 'next/router'
2-
import Link from 'next/link'
1+
import { useRouter } from "next/router";
2+
import Link from "next/link";
33

44
const CatchAll = ({ show }) => {
5-
const router = useRouter()
5+
const router = useRouter();
66

77
// This is never shown on Netlify. We just need it for NextJS to be happy,
88
// because NextJS will render a fallback HTML page.
99
if (router.isFallback) {
10-
return <div>Loading...</div>
10+
return <div>Loading...</div>;
1111
}
1212

1313
return (
1414
<div>
15-
<p>
16-
This page uses getStaticProps() to pre-fetch a TV show.
17-
</p>
15+
<p>This page uses getStaticProps() to pre-fetch a TV show.</p>
1816

19-
<hr/>
17+
<hr />
2018

2119
<h1>Show #{show.id}</h1>
22-
<p>
23-
{show.name}
24-
</p>
20+
<p>{show.name}</p>
2521

26-
<hr/>
22+
<hr />
2723

2824
<Link href="/">
2925
<a>Go back home</a>
3026
</Link>
3127
</div>
32-
)
33-
}
28+
);
29+
};
3430

3531
export async function getServerSideProps({ params }) {
3632
// The ID to render
37-
const { all } = params
38-
const id = all ? all[0] : 1
33+
const { all } = params;
34+
const id = all ? all[0] : 1;
3935

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

4339
return {
4440
props: {
45-
show: data
46-
}
47-
}
41+
show: data,
42+
},
43+
};
4844
}
4945

50-
export default CatchAll
46+
export default CatchAll;

cypress/fixtures/pages-with-optionalCatchAll/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Link from 'next/link'
1+
import Link from "next/link";
22

33
const Index = () => (
44
<div>
@@ -20,6 +20,6 @@ const Index = () => (
2020
</li>
2121
</ul>
2222
</div>
23-
)
23+
);
2424

25-
export default Index
25+
export default Index;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export default async function preview(req, res) {
2-
const { query } = req
3-
const { id } = query
2+
const { query } = req;
3+
const { id } = query;
44

55
// Enable Preview Mode by setting the cookies
6-
res.setPreviewData({})
6+
res.setPreviewData({});
77

88
// Redirect to the path from the fetched post
99
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
10-
res.writeHead(307, { Location: `/previewTest/${id}` })
11-
res.end()
10+
res.writeHead(307, { Location: `/previewTest/${id}` });
11+
res.end();
1212
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default async function exit(_, res) {
22
// Exit the current user from "Preview Mode". This function accepts no args.
3-
res.clearPreviewData()
3+
res.clearPreviewData();
44

55
// Redirect the user back to the index page.
6-
res.writeHead(307, { Location: '/' })
7-
res.end()
6+
res.writeHead(307, { Location: "/" });
7+
res.end();
88
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
export default async (req, res) => {
22
// Get the params and query string parameters
3-
const { query } = req
4-
const { params, ...queryStringParams } = query
3+
const { query } = req;
4+
const { params, ...queryStringParams } = query;
55

66
// Get the ID of the show
7-
const id = params[0]
7+
const id = params[0];
88

99
// Get the data
10-
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`);
11-
const data = await fetchRes.json();
10+
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`);
11+
const data = await fetchRes.json();
1212

1313
// If show was found, return it
14-
if(fetchRes.status == 200) {
15-
res.status(200)
16-
res.json({ params, queryStringParams, show: data })
14+
if (fetchRes.status == 200) {
15+
res.status(200);
16+
res.json({ params, queryStringParams, show: data });
1717
}
1818
// If show was not found, return error
1919
else {
20-
res.status(404)
21-
res.json({ error: "Show not found" })
20+
res.status(404);
21+
res.json({ error: "Show not found" });
2222
}
23-
}
23+
};
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
export default async (req, res) => {
22
// Get the ID of the show
3-
const { query } = req
4-
const { id } = query
3+
const { query } = req;
4+
const { id } = query;
55

66
// Get the data
7-
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`);
8-
const data = await fetchRes.json();
7+
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`);
8+
const data = await fetchRes.json();
99

1010
// If show was found, return it
11-
if(fetchRes.status == 200) {
12-
res.status(200)
13-
res.json({ show: data })
11+
if (fetchRes.status == 200) {
12+
res.status(200);
13+
res.json({ show: data });
1414
}
1515
// If show was not found, return error
1616
else {
17-
res.status(404)
18-
res.json({ error: "Show not found" })
17+
res.status(404);
18+
res.json({ error: "Show not found" });
1919
}
20-
}
20+
};

0 commit comments

Comments
 (0)