Skip to content

Commit c6715b2

Browse files
Merge branch 'canary' into eslint-update-7
2 parents 8429e50 + 8724352 commit c6715b2

File tree

8 files changed

+102
-40
lines changed

8 files changed

+102
-40
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FAUNA_ADMIN_KEY=
1+
FAUNA_CLIENT_SECRET=

examples/with-fauna/lib/fauna.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { GraphQLClient, gql } from 'graphql-request'
22

3-
const graphQLClient = new GraphQLClient('https://graphql.fauna.com/graphql', {
3+
const CLIENT_SECRET =
4+
process.env.FAUNA_ADMIN_KEY || process.env.FAUNA_CLIENT_SECRET
5+
const FAUNA_GRAPHQL_BASE_URL = 'https://graphql.fauna.com/graphql'
6+
7+
const graphQLClient = new GraphQLClient(FAUNA_GRAPHQL_BASE_URL, {
48
headers: {
5-
authorization: `Bearer ${process.env.FAUNA_ADMIN_KEY}`,
9+
authorization: `Bearer ${CLIENT_SECRET}`,
610
},
711
})
812

examples/with-fauna/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Guestbook example with Next.js and Fauna.",
66
"scripts": {
77
"dev": "next",
8-
"build": "next build",
8+
"build": "yarn setup && next build",
99
"start": "next start",
1010
"setup": "node ./scripts/setup.js"
1111
},
@@ -25,7 +25,7 @@
2525
"autoprefixer": "10.3.1",
2626
"postcss": "8.3.6",
2727
"prettier": "2.3.2",
28-
"tailwindcss": "2.2.7",
29-
"stream-to-promise": "3.0.0"
28+
"stream-to-promise": "3.0.0",
29+
"tailwindcss": "2.2.7"
3030
}
3131
}

examples/with-fauna/scripts/setup.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const request = require('request')
66
const { Client, query: Q } = require('faunadb')
77
const streamToPromise = require('stream-to-promise')
88

9-
const FAUNA_ADMIN_KEY = process.env.FAUNA_ADMIN_KEY
10-
119
const MakeLatestEntriesIndex = () =>
1210
Q.CreateIndex({
1311
name: 'latestEntries',
@@ -88,15 +86,29 @@ const MakeGuestbookKey = () =>
8886
role: Q.Role('GuestbookRole'),
8987
})
9088

91-
const askAdminKey = () => {
89+
const isDatabasePrepared = ({ client }) =>
90+
client.query(Q.Exists(Q.Index('latestEntries')))
91+
92+
const resolveAdminKey = () => {
93+
if (process.env.FAUNA_ADMIN_KEY) {
94+
return Promise.resolve(process.env.FAUNA_ADMIN_KEY)
95+
}
96+
9297
const rl = readline.createInterface({
9398
input: process.stdin,
9499
output: process.stdout,
95100
})
96101

97-
return new Promise((resolve) => {
102+
return new Promise((resolve, reject) => {
98103
rl.question('Please provide the Fauna admin key:\n', (res) => {
99104
rl.close()
105+
106+
if (!res) {
107+
return reject(
108+
new Error('You need to provide a key, closing. Try again')
109+
)
110+
}
111+
100112
resolve(res)
101113
})
102114
})
@@ -117,8 +129,6 @@ const importSchema = (adminKey) =>
117129

118130
const findImportError = (msg) => {
119131
switch (true) {
120-
case msg.startsWith('Invalid authorization header'):
121-
return 'You need to provide a secret, closing. Try again'
122132
case msg.startsWith('Invalid database secret'):
123133
return 'The secret you have provided is not valid, closing. Try again'
124134
case !msg.includes('success'):
@@ -129,17 +139,24 @@ const findImportError = (msg) => {
129139
}
130140

131141
const main = async () => {
132-
const adminKey = FAUNA_ADMIN_KEY || (await askAdminKey())
142+
const adminKey = await resolveAdminKey()
143+
const client = new Client({ secret: adminKey })
144+
145+
if (await isDatabasePrepared({ client })) {
146+
return console.info(
147+
'Fauna resources have already been prepared. ' +
148+
'If you want to install it once again, please, create a fresh database and re-run the script with the other key'
149+
)
150+
}
151+
133152
const importMsg = await importSchema(adminKey)
134153
const importErrorMsg = findImportError(importMsg)
135154

136155
if (importErrorMsg) {
137156
return Promise.reject(new Error(importErrorMsg))
138157
}
139158

140-
console.log('1. Successfully imported schema')
141-
142-
const client = new Client({ secret: adminKey })
159+
console.log('- Successfully imported schema')
143160

144161
for (const Make of [
145162
MakeLatestEntriesIndex,
@@ -149,13 +166,18 @@ const main = async () => {
149166
await client.query(Make())
150167
}
151168

152-
const { secret } = await client.query(MakeGuestbookKey())
169+
console.log('- Created Fauna resources')
170+
171+
if (process.env.FAUNA_ADMIN_KEY) {
172+
// Assume it's a Vercel environment, no need for .env.local file
173+
return
174+
}
153175

154-
console.log('2. Created Fauna resources')
176+
const { secret } = await client.query(MakeGuestbookKey())
155177

156-
await fs.promises.writeFile('.env.local', `FAUNADB_CLIENT_SECRET=${secret}\n`)
178+
await fs.promises.writeFile('.env.local', `FAUNA_CLIENT_SECRET=${secret}\n`)
157179

158-
console.log('3. Created .env.local file with secret')
180+
console.log('- Created .env.local file with secret')
159181
}
160182

161183
main().catch((err) => {

packages/next/shared/lib/router/utils/prepare-destination.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ export function matchHas(
3030
query: Params
3131
): false | Params {
3232
const params: Params = {}
33-
let initialQueryValues: string[] = []
34-
35-
if (typeof window === 'undefined') {
36-
initialQueryValues = Object.values((req as any).__NEXT_INIT_QUERY)
37-
}
38-
if (typeof window !== 'undefined') {
39-
initialQueryValues = Array.from(
40-
new URLSearchParams(location.search).values()
41-
)
42-
}
4333

4434
const allMatch = has.every((hasItem) => {
4535
let value: undefined | string
@@ -56,12 +46,7 @@ export function matchHas(
5646
break
5747
}
5848
case 'query': {
59-
// preserve initial encoding of query values
6049
value = query[key!]
61-
62-
if (initialQueryValues.includes(value || '')) {
63-
value = encodeURIComponent(value!)
64-
}
6550
break
6651
}
6752
case 'host': {

test/integration/custom-routes/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ module.exports = {
198198
key: 'post',
199199
},
200200
],
201-
destination: '/blog/:post',
201+
destination: '/blog-catchall/:post',
202202
},
203203
{
204204
source: '/blog/about',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const getStaticProps = ({ params }) => {
2+
return {
3+
props: {
4+
params,
5+
},
6+
}
7+
}
8+
9+
export const getStaticPaths = () => {
10+
return {
11+
paths: [],
12+
fallback: 'blocking',
13+
}
14+
}
15+
16+
export default function Page(props) {
17+
return <p id="props">{JSON.stringify(props)}</p>
18+
}

test/integration/custom-routes/test/index.test.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import fs from 'fs-extra'
77
import { join } from 'path'
88
import cheerio from 'cheerio'
99
import webdriver from 'next-webdriver'
10+
import escapeRegex from 'escape-string-regexp'
1011
import {
1112
launchApp,
1213
killApp,
@@ -43,15 +44,19 @@ const runTests = (isDev = false) => {
4344
for (const expected of [
4445
{
4546
post: 'first',
47+
slug: ['first'],
4648
},
4749
{
4850
post: 'hello%20world',
51+
slug: ['hello world'],
4952
},
5053
{
5154
post: 'hello/world',
55+
slug: ['hello', 'world'],
5256
},
5357
{
5458
post: 'hello%2fworld',
59+
slug: ['hello', 'world'],
5560
},
5661
]) {
5762
const { status = 200, post } = expected
@@ -68,8 +73,10 @@ const runTests = (isDev = false) => {
6873

6974
if (status === 200) {
7075
const $ = cheerio.load(await res.text())
71-
expect(JSON.parse($('#query').text())).toEqual({
72-
post: decodeURIComponent(post),
76+
expect(JSON.parse($('#props').text())).toEqual({
77+
params: {
78+
slug: expected.slug,
79+
},
7380
})
7481
}
7582
}
@@ -1107,12 +1114,30 @@ const runTests = (isDev = false) => {
11071114
]) {
11081115
route.regex = normalizeRegEx(route.regex)
11091116
}
1117+
for (const route of manifest.dataRoutes) {
1118+
route.dataRouteRegex = normalizeRegEx(route.dataRouteRegex)
1119+
}
11101120

11111121
expect(manifest).toEqual({
11121122
version: 3,
11131123
pages404: true,
11141124
basePath: '',
1115-
dataRoutes: [],
1125+
dataRoutes: [
1126+
{
1127+
dataRouteRegex: normalizeRegEx(
1128+
`^/_next/data/${escapeRegex(
1129+
buildId
1130+
)}/blog\\-catchall/(.+?)\\.json$`
1131+
),
1132+
namedDataRouteRegex: `^/_next/data/${escapeRegex(
1133+
buildId
1134+
)}/blog\\-catchall/(?<slug>.+?)\\.json$`,
1135+
page: '/blog-catchall/[...slug]',
1136+
routeKeys: {
1137+
slug: 'slug',
1138+
},
1139+
},
1140+
],
11161141
redirects: [
11171142
{
11181143
destination: '/:path+',
@@ -1817,7 +1842,7 @@ const runTests = (isDev = false) => {
18171842
source: '/has-rewrite-7',
18181843
},
18191844
{
1820-
destination: '/blog/:post',
1845+
destination: '/blog-catchall/:post',
18211846
has: [
18221847
{
18231848
key: 'post',
@@ -1868,6 +1893,14 @@ const runTests = (isDev = false) => {
18681893
post: 'post',
18691894
},
18701895
},
1896+
{
1897+
namedRegex: '^/blog\\-catchall/(?<slug>.+?)(?:/)?$',
1898+
page: '/blog-catchall/[...slug]',
1899+
regex: normalizeRegEx('^\\/blog\\-catchall\\/(.+?)(?:\\/)?$'),
1900+
routeKeys: {
1901+
slug: 'slug',
1902+
},
1903+
},
18711904
],
18721905
})
18731906
})

0 commit comments

Comments
 (0)