Commit graph

28 commits

Author SHA1 Message Date
sivtu
3913e4e396
Removed duplicate MONGODB_URI check in example (#42518)
This PR removes the duplicate check if the MONGODB_URI environment variable is set.
2022-11-05 22:17:36 +00:00
Steven
be904d79ac
Open deploy link in new window for examples (#40804)
Let's open the deploy link in a new window so the link isn't blocked
when running an an iframe, such as Stackblitz.

Previously, this would print the following error:

> Refused to display 'https://vercel.com/' in a frame because it set
'X-Frame-Options' to 'deny'
2022-09-22 09:33:36 -07:00
S0UPernova
1aa341f635
added type to clientPromise in with-mongodb/lib (#40339)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-09-08 12:44:38 +00:00
Henrik Wenz
74fb7ba03e
[Docs] Update mongodb example (#39658)
## Changelog

- Updated deps
- Migrated to typescript

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-08-21 22:38:48 +00:00
Marcos Bérgamo
c3e5caf110
docs(examples): improve DX while copying command to create new project (#38410)
* docs(examples): improve DX while copy command to create new project

* chore: apply code review

Co-authored-by: Marcos Bérgamo <Marcos.Bergamo@refinitiv.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-07-26 21:57:48 -05:00
JJ Kasper
0ab6ad5241
Update default gitignore templates (#39051) 2022-07-26 20:08:40 -05:00
Lee Robinson
54f87245dc
Update MongoDB example to use integration for deploy button. (#38738)
Rather than manually adding the environment variable.
2022-07-18 13:42:06 +00:00
Steven
57dcc9d329
Update pnpm create next-app for latest pnpm 6 and 7 (#37254)
This command changed in pnpm [6.32.13](https://github.com/pnpm/pnpm/releases/tag/v6.32.13) and [7.1.1](https://github.com/pnpm/pnpm/releases/tag/v7.1.1) so lets update it since its been a few weeks and we can expect pnpm users to update more regularly than npm users.

- Fixes https://github.com/vercel/next.js/pull/37240 
- Fixes https://github.com/vercel/next.js/pull/37045
- Fixes https://github.com/vercel/next.js/pull/37032
- Fixes https://github.com/vercel/next.js/pull/36602
- Fixes https://github.com/vercel/next.js/pull/36496
2022-05-27 21:21:40 +00:00
Tom
3e178bb801
add pnpm link to docs (#37221)
## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)


Co-authored-by: Steven <steven@ceriously.com>
2022-05-27 15:46:38 -04:00
ro11ingbutler
948128ae19
Fix typo (#36592)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-04-30 18:35:38 +00:00
Sokichi Fujita
7f798c3da0
fix(with-mongodb): Change comment of MongoDB client in getServerSideProps (#35750)
* Change comment of client in getServerSideProps

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-03-31 10:35:54 -05:00
Steven
9f9214abe5
Updated create-next-app docs to include pnpm usage (#35755)
This PR updates the docs and examples for `create-next-app` to include pnpm usage.

The following script was used to update every example README:

```js
const fs = require('fs')
const examples = fs.readdirSync('./examples')

for (let example of examples) {
    const filename = `./examples/${example}/README.md`
    const markdown = fs.readFileSync(filename, 'utf8')
    const regex = new RegExp(`^yarn create next-app --example (.*)$`, 'gm')
    const output = markdown.replace(regex, (yarn, group) => {
        const pnpm = `pnpm create next-app -- --example ${group}`
        return `${yarn}\n# or\n${pnpm}`
    })
    fs.writeFileSync(filename, output)
}
```
2022-03-30 21:03:21 +00:00
Manny Becerra
36eba95227
Fixes #33153: Updating cross-references from master to main + canary (#33198)
* copy cleanup in env. variables docs

* copy cleanup in fast refresh docs

* Supplements #33153 - updating existing cross-references to `master` branch to renamed default branch of `main`

* Supplements #33153 - updating existing cross-references to `master` branch to renamed default branch of `main`

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-01-12 02:55:35 +01:00
Kim, Harim
b290a3dc38
Fix with-mongo example by removing deprecated function (#30675)
* Remove deprecated function

* Remove useless change

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-11-30 15:50:50 -06:00
Ado Kukic
220fa9cd14
Update to use the latest MongoDB best practices to limit connection pooling issues. (#28350)
* Update to use the latest MongoDB best practices.

* lint-fix

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
2021-08-25 12:52:12 -05:00
Oscar Busk
077097b7f8
Remove licence from all example/package.json that has them (#28007)
* Add licences to all example/package.json that lack them

* Revert "Add licences to all example/package.json that lack them"

This reverts commit 5d4e25012f7334772b8ef5924bc355277e827cba.

* Update check-examples to remove `license` field from examples

* Remove `license` from all examples.

This was mentioned in vercel/next.js#27121 but it looks like it didn't end up being in the merge?

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-08-14 10:48:39 -05:00
Aryan Beezadhur
f8947b0133
Rename util to lib in with-mongodb example (#27404)
* Rename examples/with-mongodb/util/mongodb.js to examples/with-mongodb/lib/mongodb.js

* Change file import from `util` to `lib`
2021-07-22 11:32:56 -05:00
Luc Leray
f52955ec94
Clean up examples package.json (#27121)
Clean up package.json files in the `examples` directory:
- Add `private: true`
- Remove `version` (because they are irrelevant for packages that are not meant to be published)
- Remove `name` (because they are optional for packages that are not meant to be published, and when someone clones an example, they often rename it and the property becomes stale)
- Remove `author`
- Remove `description`
- Remove `license`

Also remove `with-dynamic-app-layout` example completely, since it does the same as `layout-component` (https://github.com/vercel/next.js/pull/27121#discussion_r668178408).

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-12 19:58:03 +00:00
Nick Babcock
5629223407
Update examples to use React 17 (#26133)
[With next 11 requiring react 17](https://nextjs.org/blog/next-11#upgrade-guide), most of the examples
need to be updated, so the following snippet updated all the examples to
a compatible react version.

```bash
cd examples/
fd -g 'package.json' | xargs sed -r -i 's/"react": ".*"/"react": "^17.0.2"/
fd -g 'package.json' | xargs sed -r -i 's/"react-dom": ".*"/"react-dom": "^17.0.2"/'

# exclude experimental react version
git checkout with-reason-relay/package.json
```
2021-06-16 16:43:26 +00:00
D. Kasi Pavan Kumar
2477b13799
examples/with-mongodb: avoid destructuring of environment variables. (#26029)
Greetings.

As per the [documentation](https://nextjs.org/docs/basic-features/environment-variables), we should not treat process.env as a Javscript Object & cannot destructure variables out of it. This PR avoid destructuring of environment variables in the `with-mongodb` example.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [x] Make sure the linting passes
2021-06-13 16:27:04 +00:00
Robin
c47f3d84c4
Unify installation scripts for example apps (#19808) 2021-01-24 17:05:49 +01:00
Luc Leray
b442acbe1c
Replace zeit/next.js with vercel/next.js (#20849) 2021-01-07 08:41:04 -05:00
Luc Leray
8eaabe2fb0
Fix deploy buttons URLs (#20834)
Fix all deploy button URLs in the Next.js repo to follow the following format:
```
https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/<EXAMPLE_NAME>&project-name=<EXAMPLE_NAME>&repository-name=<EXAMPLE_NAME>
```

The detailed docs for the Deploy Button can be found here: https://vercel.com/docs/more/deploy-button.

Also updates legacy Vercel import flow URLs (starting with vercel.com/import or with vercel.com/new/project), to use the new vercel.com/new URLs.

---

For example, for the `hello-world` example:

The URL is https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/hello-world&project-name=hello-world&repository-name=hello-world

And the deploy button looks like this:
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/hello-world&project-name=hello-world&repository-name=hello-world)

---

For reference, I used the following regexes to search for the incorrect URLs

```
\(https://vercel.com/import/git\?s=https://github.com/vercel/next.js/tree/canary/examples/(.*)\)
\(https://vercel.com/import/git\?c=1&s=https://github.com/vercel/next.js/tree/canary/examples/([^&]*)(.*)\)
\(https://vercel.com/import/project\?template=https://github.com/vercel/next.js/tree/canary/examples/(.*)\)
https://vercel.com/import/git
https://vercel.com/import/select-scope
https://vercel.com/import
https://vercel.com/new/project
```
2021-01-07 01:40:29 +00:00
Pier-Luc Gendreau
e6c351859f
Update with-mongodb to be TypeScript-friendly (#19383)
* Update with-mongodb to be TypeScript-friendly

I slightly modified the approach so TypeScript can correctly infer types without actually having to type anything but the global:

**index.d.ts**
```ts
import { Db, MongoClient } from "mongodb";

declare global {
  namespace NodeJS {
    interface Global {
      mongoCache: {
        conn: {
          client: MongoClient | null;
          db: Db | null;
        }
        promise: Promise<MongoClient> | null;
      };
    }
  }
}
```

* lint

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-12-28 14:40:18 -05:00
Laura Beatris
bad1448478
Style improvements on MongoDB example (#20515)
I've looked at the example code and saw some consistent issues related to code style. The changes applied to this PR fixes the following points:

- Differences of line breaks styles between multiple files
- Differences of if statements styles
- Unnecessary comment
- A typo on a JSDocs

---

There were line breaks between statements on `pages/index.js`
````
export async function getServerSideProps(context) {
  const { client } = await connectToDatabase()

  const isConnected = await client.isConnected() 

  return {
    props: { isConnected },
  }
}
```` 

And this wasn't being applied to the MongoDB utility:

````
export async function connectToDatabase() {
  if (cached.conn) return cached.conn
  if (!cached.promise) {
    const conn = {}
    const opts = {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    }
{...}
````

And also, as shown in the snippet above, there are different styles of if statements being used. 

With that being said, the reason I made this PR is because I think that this kind of inconsistent arises questions when a contributor looks to the codebase, even if this is a simple example.
2020-12-27 16:20:15 +00:00
Ash Connell
82041542e3
Fix with-mongodb hot-reload issue and race condition (#17666)
This PR fixes 2 issues with the mongodb example:

### 1. Fallable Caching Strategy

Calling `connectToDatabase()` multiple times before it's cached results in multiple connections being created. The latest one created was becoming the "cached" one and the others dissappear into the background.

This is now fixed by using **promise sharing** so that only one connection can ever be created.

### 2. Problematic Hot Reload

During development you can monitor your database connections and see that it continues to create more and more connections over time. Some users have reported their [databases reaching maximum connection limits](https://github.com/vercel/next.js/discussions/12229).

This is resolved by using `global` to store the cached connection. It's not ideal but it is necessary.
2020-10-17 00:30:38 +00:00
NorbertLuszkiewicz
c03d4931de
Simplify example usage instructions (#16678)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-08-29 22:22:02 -04:00
Ado Kukic
0152dac87f
MongoDB Example (#15029)
* MongoDB Example

* Apply suggestions from code review

* Add changes based on feedback.

* clean up code with more descriptive props

* Use MongoDB in ServerSideProps instead of separate API route

* Update examples/with-mongodb/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

* Update examples/with-mongodb/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

* Update examples/with-mongodb/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

* Update examples/with-mongodb/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

* Update examples/with-mongodb/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

* Update examples/with-mongodb/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

* Update examples/with-mongodb/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

Co-authored-by: Luis Alvarez D <luis@vercel.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-07-22 20:03:18 -05:00