|
| 1 | +--- |
| 2 | +title: Remote Storage |
| 3 | +description: Access your remote storage locally or from other Nuxt projects with our secured proxy. |
| 4 | +--- |
| 5 | + |
| 6 | +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. |
| 7 | + |
| 8 | +::note |
| 9 | +You need to have [deployed your project](/docs/getting-started/deploy) in order to use this feature. |
| 10 | +:: |
| 11 | + |
| 12 | +There are two ways to use the remote storage: |
| 13 | +- **Local development**: Access your remote storage from your local environment. |
| 14 | +- **Other Nuxt projects**: Access your remote storage from other Nuxt projects, useful if your frontend is deployed on another hosting platform. |
| 15 | + |
| 16 | +## Local Development |
| 17 | + |
| 18 | +Once your project is deployed, you can use the remote storage in your local project. |
| 19 | + |
| 20 | +Start your Nuxt project with: |
| 21 | + |
| 22 | +```bash [Terminal] |
| 23 | +npx nuxt dev --remote |
| 24 | +``` |
| 25 | + |
| 26 | +The development project will now use the remote storage from your deployed project and these logs should happen in your terminal: |
| 27 | + |
| 28 | +```bash |
| 29 | +ℹ Using remote features from https://my-project.nuxt.dev |
| 30 | +ℹ Remote storage available: database, kv, blob |
| 31 | +``` |
| 32 | + |
| 33 | +::tip{icon="i-ph-rocket-launch-duotone"} |
| 34 | +That's it! Your local project is now using the remote storage from your deployed project. |
| 35 | +:: |
| 36 | + |
| 37 | +To always use the remote storage in your local project, you can add `NUXT_HUB_REMOTE=true` in your `.env` file: |
| 38 | + |
| 39 | +```bash [.env] |
| 40 | +NUXT_HUB_REMOTE=true |
| 41 | +``` |
| 42 | + |
| 43 | +::note |
| 44 | +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`. |
| 45 | +:: |
| 46 | + |
| 47 | +### Self-hosted |
| 48 | + |
| 49 | +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. |
| 50 | + |
| 51 | +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) |
| 52 | +2. Set the same `NUXT_HUB_PROJECT_SECRET_KEY` and `NUXT_HUB_PROJECT_URL` environment variables in your local project |
| 53 | + ```bash [.env] |
| 54 | + NUXT_HUB_PROJECT_SECRET_KEY=my-project-secret-used-in-cloudflare-env |
| 55 | + NUXT_HUB_PROJECT_URL=https://my-nuxthub-project.pages.dev |
| 56 | + ``` |
| 57 | + |
| 58 | +Then, start your Nuxt project with: |
| 59 | + |
| 60 | +```bash [Terminal] |
| 61 | +npx nuxt dev --remote |
| 62 | +``` |
| 63 | +::note |
| 64 | +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. |
| 65 | +:: |
| 66 | + |
| 67 | +## Other Nuxt Projects |
| 68 | + |
| 69 | +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. |
| 70 | + |
| 71 | +To access your remote storage from another Nuxt project: |
| 72 | + |
| 73 | +1. Install `@nuxthub/core` to your project: |
| 74 | + |
| 75 | +::code-group |
| 76 | +```bash [pnpm] |
| 77 | +pnpm add @nuxthub/core |
| 78 | +``` |
| 79 | +```bash [yarn] |
| 80 | +yarn add @nuxthub/core |
| 81 | +``` |
| 82 | +```bash [npm] |
| 83 | +npm install @nuxthub/core |
| 84 | +``` |
| 85 | +```bash [bun] |
| 86 | +bun add @nuxthub/core |
| 87 | +``` |
| 88 | +:: |
| 89 | + |
| 90 | +2. Add it to the `extends` section in your `nuxt.config` and set the `remote` option to `true`: |
| 91 | + |
| 92 | +```ts [nuxt.config.ts] |
| 93 | +export default defineNuxtConfig({ |
| 94 | + extends: ['@nuxthub/core'], |
| 95 | + hub: { |
| 96 | + remote: true |
| 97 | + } |
| 98 | +}) |
| 99 | +``` |
| 100 | + |
| 101 | +3. Add the `NUXT_HUB_PROJECT_URL` and `NUXT_HUB_PROJECT_SECRET_KEY` environment variables to your project: |
| 102 | + |
| 103 | +```bash [.env] |
| 104 | +NUXT_HUB_PROJECT_URL=https://my-nuxthub-project.pages.dev |
| 105 | +NUXT_HUB_PROJECT_SECRET_KEY=my-project-secret-used-in-cloudflare-env |
| 106 | +``` |
| 107 | + |
| 108 | +If you haven't, set the `NUXT_HUB_PROJECT_SECRET_KEY` environment variable in your NuxtHub deployed project and make sure to redeploy. |
| 109 | +
|
| 110 | +::tip{icon="i-ph-rocket-launch-duotone"} |
| 111 | +You can now use the remote storage from your NuxtHub project in your other Nuxt project (both locally and in production). |
| 112 | +:: |
0 commit comments