Skip to content

Commit 3ff7e8b

Browse files
authored
Merge branch 'canary' into fix/empty-headers
2 parents a270697 + 4d5eaf0 commit 3ff7e8b

File tree

134 files changed

+655
-246
lines changed

Some content is hidden

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

134 files changed

+655
-246
lines changed

.github/workflows/build_test_deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
path: ./*
105105
key: ${{ github.sha }}
106106

107-
- run: node run-tests.js --timings --type unit -g 1/1
107+
- run: node run-tests.js --type unit
108108
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
109109

110110
testIntegration:

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ stages:
111111
path: $(System.DefaultWorkingDirectory)
112112
displayName: Cache Build
113113
- script: |
114-
node run-tests.js -g 1/1 --timings --azure --type unit
114+
node run-tests.js --type unit
115115
displayName: 'Run tests'
116116
# TODO: investigate re-enabling when stability matches running in
117117
# tests in ubuntu environment

data.sqlite

Whitespace-only changes.

docs/api-routes/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ For new projects, you can build your entire API with API Routes. If you have an
5555

5656
## Caveats
5757

58-
- API Routes [do not specify CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), meaning they are **same-origin only** by default. You can customize such behavior by wrapping the request handler with the [cors middleware](/docs/api-routes/api-middlewares.md#connectexpress-middleware-support).
58+
- API Routes [do not specify CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), meaning they are **same-origin only** by default. You can customize such behavior by wrapping the request handler with the [CORS middleware](/docs/api-routes/api-middlewares.md#connectexpress-middleware-support).
5959
- API Routes can't be used with [`next export`](/docs/advanced-features/static-html-export.md)
6060

6161
## Related

examples/with-couchbase/util/couchbase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import couchbase from 'couchbase'
1+
import * as couchbase from 'couchbase'
22

33
const COUCHBASE_USER = process.env.COUCHBASE_USER
44
const COUCHBASE_PASSWORD = process.env.COUCHBASE_PASSWORD
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ESS_CLOUD_ID=
2+
ESS_CLOUD_USERNAME=
3+
ESS_CLOUD_PASSWORD=
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# next.js
10+
/.next/
11+
/out/
12+
13+
# production
14+
/build
15+
16+
# misc
17+
.DS_Store
18+
19+
# debug
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
24+
# local env files
25+
.env.local
26+
.env.development.local
27+
.env.test.local
28+
.env.production.local
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
## Example app using Elasticsearch
2+
3+
[Elasticsearch](https://www.elastic.co/elasticsearch) is a distributed, RESTful search and analytics engine. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. This example will show you how to connect to and use Elasticsearch as your search backend for your Next.js app.
4+
5+
If you want to learn more about Elasticsearch, visit the following pages:
6+
7+
- [Elastic Stack](https://https://www.elastic.co/products)
8+
- [Elastic Documentation](https://elastic.co/docs)
9+
10+
## Deploy your own
11+
12+
Once you have access to the environment variables you'll need, deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
13+
14+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-elasticsearch&project-name=with-elasticsearch&repository-name=with-elasticsearch&env=ESS_CLOUD_ID,ESS_CLOUD_USERNAME,ESS_CLOUD_PASSWORD&envDescription=Required%20to%20connect%20the%20app%20with%Elasticsearch)
15+
16+
## How to use
17+
18+
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
19+
20+
```bash
21+
npx create-next-app --example with-elasticsearch with-elasticsearch-app
22+
# or
23+
yarn create next-app --example with-elasticsearch with-elasticsearch-app
24+
```
25+
26+
## Configuration
27+
28+
### Set up Elasticsearch
29+
30+
Set up a Elasticsearch either locally or with [Elastic Cloud for free](https://elastic.co/cloud).
31+
32+
### Set up environment variables
33+
34+
Copy the `env.local.example` file in this directory to `.env.local` (which will be ignored by Git):
35+
36+
```bash
37+
cp .env.local.example .env.local
38+
```
39+
40+
Set each variable on `.env.local`:
41+
42+
- `ESS_CLOUD_ID` - URL for the Elasticsearch instance, if you are using [Elastic Cloud](https://elastic.co/cloud) you can find this in the Elastic Cloud console.
43+
- `ESS_CLOUD_USERNAME` - The username for the Elasticsearch instance you have created, if you are using default user it would be `elastic`.
44+
- `ESS_CLOUD_PASSWORD` - Password for the Elasticsearch instance
45+
46+
### Run Next.js in development mode
47+
48+
```bash
49+
npm install
50+
npm run dev
51+
52+
# or
53+
54+
yarn install
55+
yarn dev
56+
```
57+
58+
Your app should be up and running on [http://localhost:3000](http://localhost:3000)! If it doesn't work, post on [GitHub discussions](https://github.com/vercel/next.js/discussions).
59+
60+
Please ensure that you have configured the env variables in the `.env.local`, if not you will see the message "You are not connected to Elasticsearch!" in the main page.
61+
62+
If you see that you are connected, you can refer to the [Elasticsearch NodeJS language client docs](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html) for further instructions on querying Elasticsearch.
63+
64+
## Deploy on Vercel
65+
66+
You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
67+
68+
#### Deploy Your Local Project
69+
70+
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example).
71+
72+
**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.
73+
74+
#### Deploy from Our Template
75+
76+
Alternatively, you can deploy using our template by clicking on the Deploy button below.
77+
78+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-elasticsearch&project-name=with-elasticsearch&repository-name=with-elasticsearch&env=ESS_CLOUD_ID,ESS_CLOUD_USERNAME,ESS_CLOUD_PASSWORD&envDescription=Required%20to%20connect%20the%20app%20with%20Elasticsearch)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Client } from '@elastic/elasticsearch'
2+
3+
export async function connectToElasticsearch() {
4+
const ESS_CLOUD_ID = process.env.ESS_CLOUD_ID
5+
const ESS_CLOUD_USERNAME = process.env.ESS_CLOUD_USERNAME
6+
const ESS_CLOUD_PASSWORD = process.env.ESS_CLOUD_PASSWORD
7+
8+
if (!ESS_CLOUD_ID || !ESS_CLOUD_USERNAME || !ESS_CLOUD_PASSWORD) {
9+
return 'ERR_ENV_NOT_DEFINED'
10+
}
11+
12+
return new Client({
13+
cloud: {
14+
id: ESS_CLOUD_ID,
15+
},
16+
auth: {
17+
username: ESS_CLOUD_USERNAME,
18+
password: ESS_CLOUD_PASSWORD,
19+
},
20+
})
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "next dev",
5+
"build": "next build",
6+
"start": "next start",
7+
"lint": "next lint"
8+
},
9+
"dependencies": {
10+
"@elastic/elasticsearch": "^7.14.0",
11+
"next": "latest",
12+
"react": "^17.0.2",
13+
"react-dom": "^17.0.2"
14+
}
15+
}

0 commit comments

Comments
 (0)