Skip to content

Commit addb5b4

Browse files
committed
Format code with prettier
Make our code look consistent and beautiful :)
1 parent 28045b7 commit addb5b4

File tree

24 files changed

+496
-472
lines changed

24 files changed

+496
-472
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# next-on-netlify build output
2+
out_functions/
3+
out_publish/
4+
15
# Logs
26
logs
37
*.log

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
// Target must be serverless
3-
target: 'serverless'
3+
target: "serverless",
44
};

pages/_app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* wanted to add some CSS, so that the demo looks a little prettier :)
44
******************************************************************************/
55

6-
import '../styles.css'
6+
import "../styles.css";
77

88
// This default export is required in a new `pages/_app.js` file.
99
export default function MyApp({ Component, pageProps }) {
10-
return <Component {...pageProps} />
10+
return <Component {...pageProps} />;
1111
}

pages/api/[...slug].js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
export default async (req, res) => {
22
// Get the ID to show
3-
const { query } = req
4-
const { slug } = query
5-
const id = slug[0]
3+
const { query } = req;
4+
const { slug } = query;
5+
const id = slug[0];
66

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

1111
// Show could not be found
12-
if(fetchRes.status > 200) {
13-
res.status(404)
12+
if (fetchRes.status > 200) {
13+
res.status(404);
1414
res.json({
15-
error: 'Show could not be found :('
16-
})
17-
return
15+
error: "Show could not be found :(",
16+
});
17+
return;
1818
}
1919

20-
res.status(200)
20+
res.status(200);
2121
res.json({
22-
title: 'API route: catch-all endpoint',
23-
description: 'This endpoint fetches a TV show from an external API. ' +
24-
'It is a catch-all endpoint. ' +
25-
'The first URL parameter determines the ID of the show to fetch. ' +
26-
'You can change the URL to anything else, such as /api/1871/whatever/path/you/want',
22+
title: "API route: catch-all endpoint",
23+
description:
24+
"This endpoint fetches a TV show from an external API. " +
25+
"It is a catch-all endpoint. " +
26+
"The first URL parameter determines the ID of the show to fetch. " +
27+
"You can change the URL to anything else, such as /api/1871/whatever/path/you/want",
2728
slug: slug,
28-
viewCode: 'https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/[...slug].js',
29-
goHome: 'https://next-on.netlify.app',
29+
viewCode:
30+
"https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/[...slug].js",
31+
goHome: "https://next-on.netlify.app",
3032
show: {
3133
id: show.id,
3234
name: show.name,
@@ -35,7 +37,7 @@ export default async (req, res) => {
3537
status: show.status,
3638
premiered: show.premiered,
3739
officialSite: show.officialSite,
38-
averageRating: show.rating?.average
39-
}
40-
})
41-
}
40+
averageRating: show.rating?.average,
41+
},
42+
});
43+
};

pages/api/[id].js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
export default async (req, res) => {
22
// Get the ID to show
3-
const { query } = req
4-
const { id } = query
3+
const { query } = req;
4+
const { id } = query;
55

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

1010
// Show could not be found
11-
if(fetchRes.status > 200) {
12-
res.status(404)
11+
if (fetchRes.status > 200) {
12+
res.status(404);
1313
res.json({
14-
error: 'Show could not be found :('
15-
})
16-
return
14+
error: "Show could not be found :(",
15+
});
16+
return;
1717
}
1818

19-
res.status(200)
19+
res.status(200);
2020
res.json({
21-
title: 'API route: dynamic endpoint',
22-
description: 'This endpoint fetches a TV show from an external API. ' +
23-
'The ID is set in the URL: /api/:id. ' +
24-
'You can change the ID to any number between 1-10000. Try it!',
25-
viewCode: 'https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/[id].js',
26-
goHome: 'https://next-on.netlify.app',
21+
title: "API route: dynamic endpoint",
22+
description:
23+
"This endpoint fetches a TV show from an external API. " +
24+
"The ID is set in the URL: /api/:id. " +
25+
"You can change the ID to any number between 1-10000. Try it!",
26+
viewCode:
27+
"https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/[id].js",
28+
goHome: "https://next-on.netlify.app",
2729
show: {
2830
id: show.id,
2931
name: show.name,
@@ -32,7 +34,7 @@ export default async (req, res) => {
3234
status: show.status,
3335
premiered: show.premiered,
3436
officialSite: show.officialSite,
35-
averageRating: show.rating?.average
36-
}
37-
})
38-
}
37+
averageRating: show.rating?.average,
38+
},
39+
});
40+
};

pages/api/enterPreview/[id].js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export default (req, res) => {
22
// Get the ID to redirect to
3-
const { query } = req
4-
const { id } = query
3+
const { query } = req;
4+
const { id } = query;
55

66
// Enable Preview Mode by setting preview mode cookies
7-
res.setPreviewData({})
7+
res.setPreviewData({});
88

99
// Redirect to a page with support for preview mode
10-
res.writeHead(307, { Location: `/previewMode/${id}` })
11-
res.end()
12-
}
10+
res.writeHead(307, { Location: `/previewMode/${id}` });
11+
res.end();
12+
};

pages/api/exitPreview/[id].js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export default (req, res) => {
22
// Get the ID to redirect to
3-
const { query } = req
4-
const { id } = query
3+
const { query } = req;
4+
const { id } = query;
55

66
// Clear the preview mode cookies.
77
// This function accepts no arguments.
8-
res.clearPreviewData()
8+
res.clearPreviewData();
99

1010
// Redirect to a page with support for preview mode
11-
res.writeHead(307, { Location: `/previewMode/${id}` })
12-
res.end()
13-
}
11+
res.writeHead(307, { Location: `/previewMode/${id}` });
12+
res.end();
13+
};

pages/api/redirect.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export default (req, res) => {
2-
res.writeHead(307, { Location: '/you-have-been-redirected' })
3-
res.end()
4-
}
2+
res.writeHead(307, { Location: "/you-have-been-redirected" });
3+
res.end();
4+
};

pages/api/show.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export default (req, res) => {
2-
res.status(200)
2+
res.status(200);
33
res.json({
4-
title: 'API route: basic endpoint',
5-
description: 'API endpoints are handled by Netlify Functions. ' +
6-
'You can run all sorts of code and return all sorts of responses. ' +
7-
'This one simply returns some JSON.',
8-
viewCode: 'https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/show.js',
9-
goHome: 'https://next-on.netlify.app'
10-
})
11-
}
4+
title: "API route: basic endpoint",
5+
description:
6+
"API endpoints are handled by Netlify Functions. " +
7+
"You can run all sorts of code and return all sorts of responses. " +
8+
"This one simply returns some JSON.",
9+
viewCode:
10+
"https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/show.js",
11+
goHome: "https://next-on.netlify.app",
12+
});
13+
};

pages/api/xml.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default (req, res) => {
2-
res.status(200)
3-
res.setHeader('Content-Type', 'application/xml')
2+
res.status(200);
3+
res.setHeader("Content-Type", "application/xml");
44
res.send(
55
`<?xml version="1.0" encoding="UTF-8"?>
66
<root>
@@ -9,5 +9,5 @@ export default (req, res) => {
99
<view_code>https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/xml.js</view_code>
1010
<go_home>https://next-on.netlify.app</go_home>
1111
</root>`
12-
)
13-
}
12+
);
13+
};

pages/getInitialProps/[...slug].js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,83 @@
1-
import Error from 'next/error'
2-
import Link from 'next/link'
1+
import Error from "next/error";
2+
import Link from "next/link";
33

44
const CatchAllShow = ({ errorCode, show, slug }) => {
5-
65
// If show was not found, render 404 page
76
if (errorCode) {
8-
return <Error statusCode={errorCode} />
7+
return <Error statusCode={errorCode} />;
98
}
109

1110
// Otherwise, render the page
1211
return (
1312
<>
1413
<h1>getInitialProps: with catch-all routing</h1>
1514
<p>
16-
This page uses getInitialProps() to fetch a TV show from an API.<br/>
15+
This page uses getInitialProps() to fetch a TV show from an API.
16+
<br />
1717
It uses catch-all routing.
1818
</p>
1919
<p>
2020
URL parameters are made available in getInitialProps:
21-
<br/>
21+
<br />
2222
{slug.map((item, index) => (
2323
<span key={index}>
24-
[{index}]: {item}<br/>
24+
[{index}]: {item}
25+
<br />
2526
</span>
2627
))}
2728
</p>
29+
<p>The first URL parameter determines the ID of the TV show to fetch.</p>
2830
<p>
29-
The first URL parameter determines the ID of the TV show to fetch.
30-
</p>
31-
<p>
32-
You can change the URL to anything else, such as /getInitialProps/1871/whatever/path/you/want. Try it!
31+
You can change the URL to anything else, such as
32+
/getInitialProps/1871/whatever/path/you/want. Try it!
3333
</p>
3434
<a
3535
href="https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/getInitialProps/[...slug].js"
36-
target="_blank">
36+
target="_blank"
37+
>
3738
View code on GitHub
3839
</a>
3940

40-
<hr/>
41+
<hr />
4142

42-
<h2>Show #{show.id}: {show.name}</h2>
43-
<a
44-
href={`https://api.tvmaze.com/shows/${show.id}`}
45-
target='_blank'>
43+
<h2>
44+
Show #{show.id}: {show.name}
45+
</h2>
46+
<a href={`https://api.tvmaze.com/shows/${show.id}`} target="_blank">
4647
https://api.tvmaze.com/shows/{show.id}
4748
</a>
4849

4950
<p>
50-
Type: {show.type} <br/>
51-
Language: {show.language} <br/>
52-
Status: {show.status} <br/>
53-
Premiered: {show.premiered} <br/>
54-
Official Site: {show.officialSite} <br/>
51+
Type: {show.type} <br />
52+
Language: {show.language} <br />
53+
Status: {show.status} <br />
54+
Premiered: {show.premiered} <br />
55+
Official Site: {show.officialSite} <br />
5556
Rating (average): {show.rating?.average}
5657
</p>
5758

58-
<hr/>
59+
<hr />
5960

6061
<Link href="/">
6162
<a>Go back home</a>
6263
</Link>
6364
</>
64-
)
65-
}
65+
);
66+
};
6667

6768
CatchAllShow.getInitialProps = async ({ query }) => {
6869
// Get the ID to render
69-
const { slug } = query
70-
const id = slug[0]
70+
const { slug } = query;
71+
const id = slug[0];
7172

7273
// Get the show
7374
const res = await fetch(`https://api.tvmaze.com/shows/${id}`);
7475
const show = await res.json();
7576

7677
// Set error code if show could not be found
77-
const errorCode = res.status > 200 ? res.status : false
78+
const errorCode = res.status > 200 ? res.status : false;
7879

79-
return { errorCode, show, slug }
80-
}
80+
return { errorCode, show, slug };
81+
};
8182

82-
export default CatchAllShow
83+
export default CatchAllShow;

0 commit comments

Comments
 (0)