Commit graph

13 commits

Author SHA1 Message Date
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