Directus Cloud
Nuxtus can be used with a local copy of Directus
or the cloud hosted version of Directus Cloud. To get started you need to have an existing Directus Cloud
account correctly configured and then select the "Directus Cloud" option when creating a new Nuxtus project.
Configuring Directus
Currently you can't add third-party extensions to a Directus Cloud
project so you will need to do this manually.
- Login to your Directus Cloud account.
- Create a new project (or select an existing one). - If creating a new project your credentials will be emailed to you. You will need these to configure Nuxtus.
- If creating a new
Nuxtus
project from scratch now runnpx create-nuxtus app-name
and completeNuxtus
installation. Alternatively, follow the instructions below for manually switching to Nuxtus Cloud - (optional, but recommended) Edit
./client/nuxtus.config.ts
and addlocaltunnel: { subdomain: 'anOriginalName' }
so you always get the same localtunnel subdomain. Otherwise, you will need to update the Nuxtus URL in your Flows each time you restart the local Nuxt server. - Login to your Directus project
- Click on Settings > Flows and
Create Flow
- Fill in the flow details, anything will do here but name it something like
Nuxtus - Create Collection
so you can easily identify it later. - Click the right arrow to continue and then select
Event Hook
- For
type
selectAction (non-blocking)
- Then select
items.create
from theScope
dropdown - Select
Directus Collections
from the Collections list - Then click the tick to save the flow.
- On the flow diagram screen click the + icon at the end of the arrow coming out of the
Event Hook
box we just created. - Enter Name:
Nuxtus create
then selectWebhook / Request URL
- Change the
method
toPOST
and paste the external Nuxt URL (from step 3 above or step 4 from manually switching to Nuxtus Cloud) into theURL
field and add/api/directus/collection
to the end. For example:https://some-random-string.loca.lt/api/directus/collection
- Add a header with a header of
Bypass-Tunnel-Reminder
and a value oftrue
(the value can actually be anything) - In the
Request Body
textarea enter
{{ $trigger.payload }}
then click the tick top right.
- Click the tick again to save the entire flow.
Now we have a flow that will tell Nuxt every time you create a new collection in Directus. Next we need to make another flow to let Nuxt know when fields are created, added or deleted to update the Typescript types.
- Click on Settings > Flows and
Create Flow
- Name this Flow
Nuxtus - Update Types
(the rest of the fields can be anything). Click right arrow. - Select
Event Hook
andAction (Non-blocking)
- For scope select
items.create
anditems.update
anditems.delete
- For "Collections" choose
Directus Fields
then click the tick at the top right - Click plus and then select
Webhook / Request URL
- Change the
method
toPOST
and paste the external Nuxt URL (from step 3 above or step 4 from manually switching to Nuxtus Cloud) into theURL
field and add/api/directus/field
to the end. For example:https://some-random-string.loca.lt/api/directus/field
- Add a header with a header of
Bypass-Tunnel-Reminder
and a value oftrue
(the value can actually be anything) - In the
Request Body
textarea enter
{{ $trigger.payload }}
then click the tick top right. 10. Click the tick again to save the entire flow.
That's it! You can now create Collections in Directus Cloud and have fully typed pages appear in your local Nuxt environment!
Manually switching to Nuxtus Cloud
If you already have a Nuxtus project and want to switch to using Directus Cloud you can do this manually.
- Edit
/client/.env
and update theDIRECTUS_URL
to yourDirectus Cloud
project URL and the email/password to yours.
Encase the password in double quotes ("'s) to avoid special characters not being sent
- Install the
@nuxtus/nuxt-localtunnel
- Start Nuxt in development mode
npm run dev
. Make note of the external URL provided. - Continue with the Configuring Directus steps above.