-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support remote storage in production (#17)
* feat: support remote storage in production * chore: remove console.log
- Loading branch information
Showing
24 changed files
with
224 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
docs/content/docs/1.getting-started/4.remote-storage.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
title: Remote Storage | ||
description: Access your remote storage locally or from other Nuxt projects with our secured proxy. | ||
--- | ||
|
||
One of the main features of NuxtHub is the ability to access your remote storage from your local environment or from other Nuxt projects. This is made possible by our secured proxy system. | ||
|
||
::note | ||
You need to have [deployed your project](/docs/getting-started/deploy) in order to use this feature. | ||
:: | ||
|
||
There are two ways to use the remote storage: | ||
- **Local development**: Access your remote storage from your local environment. | ||
- **Other Nuxt projects**: Access your remote storage from other Nuxt projects, useful if your frontend is deployed on another hosting platform. | ||
|
||
## Local Development | ||
|
||
Once your project is deployed, you can use the remote storage in your local project. | ||
|
||
Start your Nuxt project with: | ||
|
||
```bash [Terminal] | ||
npx nuxt dev --remote | ||
``` | ||
|
||
The development project will now use the remote storage from your deployed project and these logs should happen in your terminal: | ||
|
||
```bash | ||
ℹ Using remote features from https://my-project.nuxt.dev | ||
ℹ Remote storage available: database, kv, blob | ||
``` | ||
|
||
::tip{icon="i-ph-rocket-launch-duotone"} | ||
That's it! Your local project is now using the remote storage from your deployed project. | ||
:: | ||
|
||
To always use the remote storage in your local project, you can add `NUXT_HUB_REMOTE=true` in your `.env` file: | ||
|
||
```bash [.env] | ||
NUXT_HUB_REMOTE=true | ||
``` | ||
|
||
::note | ||
NuxtHub will use the remote storage from your deployed project **as long as you are logged in with the [NuxtHub CLI](https://github.com/nuxt-hub/cli) and the local project is linked to a NuxtHub project** with `nuxthub link` or `nuxthub deploy`. | ||
:: | ||
|
||
### Self-hosted | ||
|
||
If you are not using the [NuxtHub Console](https://console.hub.nuxt.com) to manage your project, you can still use the remote storage in your local development environment. | ||
|
||
1. Set the `NUXT_HUB_PROJECT_SECRET_KEY` environment variable in your Cloudflare Pages project settings and retry the last deployment to apply the changes (you can generate a random secret on https://www.uuidgenerator.net/version4) | ||
2. Set the same `NUXT_HUB_PROJECT_SECRET_KEY` and `NUXT_HUB_PROJECT_URL` environment variables in your local project | ||
```bash [.env] | ||
NUXT_HUB_PROJECT_SECRET_KEY=my-project-secret-used-in-cloudflare-env | ||
NUXT_HUB_PROJECT_URL=https://my-nuxthub-project.pages.dev | ||
``` | ||
|
||
Then, start your Nuxt project with: | ||
|
||
```bash [Terminal] | ||
npx nuxt dev --remote | ||
``` | ||
::note | ||
NuxtHub will use the remote data from your deployed project as long as the `NUXT_HUB_PROJECT_SECRET_KEY` matches the one in your Cloudflare Pages project settings. | ||
:: | ||
|
||
## Other Nuxt Projects | ||
|
||
It is possible to use the remote storage from another Nuxt project. This can be useful if your frontend is deployed on another hosting platform and you want to use your NuxtHub as your backend. | ||
|
||
To access your remote storage from another Nuxt project: | ||
|
||
1. Install `@nuxthub/core` to your project: | ||
|
||
::code-group | ||
```bash [pnpm] | ||
pnpm add @nuxthub/core | ||
``` | ||
```bash [yarn] | ||
yarn add @nuxthub/core | ||
``` | ||
```bash [npm] | ||
npm install @nuxthub/core | ||
``` | ||
```bash [bun] | ||
bun add @nuxthub/core | ||
``` | ||
:: | ||
|
||
2. Add it to the `extends` section in your `nuxt.config` and set the `remote` option to `true`: | ||
|
||
```ts [nuxt.config.ts] | ||
export default defineNuxtConfig({ | ||
extends: ['@nuxthub/core'], | ||
hub: { | ||
remote: true | ||
} | ||
}) | ||
``` | ||
|
||
3. Add the `NUXT_HUB_PROJECT_URL` and `NUXT_HUB_PROJECT_SECRET_KEY` environment variables to your project: | ||
|
||
```bash [.env] | ||
NUXT_HUB_PROJECT_URL=https://my-nuxthub-project.pages.dev | ||
NUXT_HUB_PROJECT_SECRET_KEY=my-project-secret-used-in-cloudflare-env | ||
``` | ||
|
||
If you haven't, set the `NUXT_HUB_PROJECT_SECRET_KEY` environment variable in your NuxtHub deployed project and make sure to redeploy. | ||
::tip{icon="i-ph-rocket-launch-duotone"} | ||
You can now use the remote storage from your NuxtHub project in your other Nuxt project (both locally and in production). | ||
:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.