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
Nuxtusproject from scratch now runnpx create-nuxtus app-nameand completeNuxtusinstallation. Alternatively, follow the instructions below for manually switching to Nuxtus Cloud - (optional, but recommended) Edit
./client/nuxtus.config.tsand 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 Collectionso you can easily identify it later. - Click the right arrow to continue and then select
Event Hook - For
typeselectAction (non-blocking) - Then select
items.createfrom theScopedropdown - Select
Directus Collectionsfrom 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 Hookbox we just created. - Enter Name:
Nuxtus createthen selectWebhook / Request URL - Change the
methodtoPOSTand paste the external Nuxt URL (from step 3 above or step 4 from manually switching to Nuxtus Cloud) into theURLfield and add/api/directus/collectionto the end. For example:https://some-random-string.loca.lt/api/directus/collection - Add a header with a header of
Bypass-Tunnel-Reminderand a value oftrue(the value can actually be anything) - In the
Request Bodytextarea 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 HookandAction (Non-blocking) - For scope select
items.createanditems.updateanditems.delete - For "Collections" choose
Directus Fieldsthen click the tick at the top right - Click plus and then select
Webhook / Request URL - Change the
methodtoPOSTand paste the external Nuxt URL (from step 3 above or step 4 from manually switching to Nuxtus Cloud) into theURLfield and add/api/directus/fieldto the end. For example:https://some-random-string.loca.lt/api/directus/field - Add a header with a header of
Bypass-Tunnel-Reminderand a value oftrue(the value can actually be anything) - In the
Request Bodytextarea 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/.envand update theDIRECTUS_URLto yourDirectus Cloudproject 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.