Skip to content

Commit 05d6ff8

Browse files
authored
feat: support remote storage in production (#17)
* feat: support remote storage in production * chore: remove console.log
1 parent 3ba981b commit 05d6ff8

24 files changed

+224
-144
lines changed

docs/content/docs/1.getting-started/2.installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Installation
3-
description: Add NuxtHub to your Nuxt project.
3+
description: Learn how to create a NuxtHub project or add it to your current Nuxt project.
44
---
55

66
## Quickstart

docs/content/docs/1.getting-started/3.deploy.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,6 @@ The command will:
2828
Install the [NuxtHub CLI](https://github.com/nuxt-hub/cli) globally with: `npm i -g nuxthub`.
2929
::
3030

31-
### Remote Storage
32-
33-
Once your project is deployed, you can use the remote storage in your local project.
34-
35-
Start your Nuxt project with:
36-
37-
```bash [Terminal]
38-
npx nuxt dev --remote
39-
```
40-
41-
Your development project will now use the remote storage from your deployed project.
42-
43-
To always use the remote storage in your local project, update your `nuxt.config.ts`:
44-
45-
```ts [nuxt.config.ts]
46-
export default defineNuxtConfig({
47-
hub: {
48-
// Always use remote storage in development
49-
remote: true
50-
}
51-
})
52-
```
53-
54-
::note
55-
Nuxt 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**.
56-
::
57-
5831
## Self-hosted
5932

6033
You can deploy your project on your own Cloudflare account without using the NuxtHub Console.
@@ -80,25 +53,3 @@ Once your project is created, open the `Settings -> Functions` tab and set:
8053
Go back to the `Deployment` tab and retry the last deployment by clicing on `...` then `Retry deployment`.
8154

8255
Once the deployment is done, NuxtHub should be ready to use in your deployed project.
83-
84-
### Remote Storage
85-
86-
To enable remote storage in your self-hosted project, you need to create a secret key.
87-
88-
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)
89-
2. Set the same `NUXT_HUB_PROJECT_SECRET_KEY` and `NUXT_HUB_PROJECT_URL` environment variables in your local project
90-
91-
```bash [.env]
92-
NUXT_HUB_PROJECT_SECRET_KEY=my-project-secret-used-in-cloudflare-env
93-
NUXT_HUB_PROJECT_URL=https://my-nuxthub-project.pages.dev
94-
```
95-
96-
Then, start your Nuxt project with:
97-
98-
```bash [Terminal]
99-
npx nuxt dev --remote
100-
```
101-
102-
::warning
103-
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.
104-
::
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
::

docs/content/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ features:
6161
icon: 'i-ph-shapes-duotone'
6262
to: '/docs/storage/blob'
6363
- title: 'Remote Storage'
64-
description: 'Access your remote storage locally with our secured proxy, work with your data as if they were local.'
64+
description: 'Access your remote storage locally or from other Nuxt projects with our secured proxy, work with your data as if they were local.'
6565
icon: 'i-ph-plugs-connected-duotone'
6666
to: '/docs/getting-started/deploy#remote-storage'
6767
target: '_blank'

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"dev:prepare": "nuxi prepare playground",
2828
"dev": "nuxi dev playground",
2929
"dev:build": "nuxi build playground",
30-
"docs": "nuxi dev docs",
30+
"docs": "PORT=4000 nuxi dev docs",
3131
"docs:build": "nuxi generate docs",
3232
"release": "npm run lint && npm run test && changelogen --release && npm publish && git push --follow-tags",
3333
"lint": "eslint .",
@@ -66,4 +66,4 @@
6666
"vitest": "^1.3.1",
6767
"wrangler": "^3.31.0"
6868
}
69-
}
69+
}

playground/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vercel

playground/nuxt.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export default defineNuxtConfig({
33
extends: [
44
'../'
55
],
6+
hub: {
7+
remote: true
8+
},
69
modules: [
710
'@nuxt/ui',
811
'@kgierke/nuxt-basic-auth'

0 commit comments

Comments
 (0)