Code Monkey home page Code Monkey logo

directus-mysql-template's Introduction

Docker with Directus / MySQL / Adminer / GraphQL

This package contains everything you need to get up and running with Directus CMS with a MySQL backend, plus an interactive GraphQL playground to help you develop your API queries.

Requirements: you need Docker and Node installed on your machine:

Quick Install:

The easiest way to get up and running is to open a terminal session and run:

npx create-directus-docker@latest <my-project>

Then, just follow the on-screen prompts.

Manual Install

As an alternative, you can install this package by following these steps. Once you've installed Node and Docker, and have Docker Desktop running on your machine:

  1. Open a terminal session:
    Mac: Go to /Applications/Utilities then double-click Terminal.
    Windows: Click 'Start' taskbar button, Select 'All apps', scroll down and select 'Terminal'
  2. CD into the parent directory where you'd like to install this, ie cd '~/Documents/My-Folder'.
  3. From there, run:
    git clone https://github.com/rollmug/directus-mysql-template.git
    OR, if you don't have git installed, manually download it here and unzip it.
  4. Navigate into the folder you just downloaded, ie cd 'directus-mysql-template'

Configure your Directus/MySQL setup:

  1. Within the directus-mysql-template directory, run npm install
  2. Lastly, run npm start. The wizard will walk you through the config, and automatically launch all containers for you.

Note that you'll only have to do these two steps the first time you run this.

Seeding MySQL data

If you want to seed your database with data on first launch, place your .sql file(s) in the "init" directory at the root of this package. MySQL will run any files in this directory the first time it launches.

Snapshot the Data Model

Directus can automatically generate a snapshot of your current data model in YAML format. This includes all collections, fields, and relations, and their configuration. This snapshot can be checked in version control and shared with your team. To generate the snapshot, run:

npm run snapshot

The 'directus' container must be running in order to take a snapshot.

Apply a Snapshot

To overwrite the current Directus instance with the data model specified in that snapshot, you can apply a snapshot by running:

npm run snapshot-apply --snapshot=snapshot-file.yaml

Change the name of the file in the command to match an actual snapshot file in your 'snapshots' directory.

By applying the snapshot, Directus will auto-detect the changes required to make the current instance up to date with the proposed data model in the snapshot file, and will run the required migrations to the database to make it match the snapshot. This is useful when migrating to/from another directus instance.

It is recommended that you test this first by doing a dry-run like this:

npm run snapshot-test --snapshot=snapshot-file.yaml

Starting/stopping with Docker Compose

To stop your running containers, simply run docker compose down in your terminal from within the project directory. All containers will be stopped.

To restart your stopped containers, you can let the helper app do it for you:

npm start

Or you can follow this sequence:

docker compose up mysql -d

Then wait 10-20 seconds (for MySQL to boot), then type:

docker compose up -d

Boom! You're done. Now you can access the URLS from here:

Directus CMS: http://localhost:8055
GraphQL Playground: http://localhost:4000/graphql
Adminer (for MySQL): http://localhost:8080

Check on running containers:

Simply run docker compose ps to see the status of running containers. Or, run docker compose ps -a to see all containers, running or not.

CORS problems on localhost

When using the GraphiQL playground on localhost, you'll run into some browser problems related to CORS. Here's how to get around it:

Safari:

  1. Enable the developer menu by opening up Settings > Advanced, then check "Show Develop bar in menu"
  2. Click the Develop menu and check "Disable Cross-Origin Restrictions"

Chrome

Temporarily Disable CORS in Chrome (MacOS):

  1. Quit Chrome
  2. Open terminal and run:

open -n -a "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security

Windows:

  1. Right click on desktop, add new shortcut
  2. Add the target as "[PATH_TO_CHROME]\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp
  3. Click OK

Firefox:

For Firefox you can simply install CORS Everywhere addon.

Examples of getting an auth token for API:

curl -X POST localhost:8055/auth/login -H 'Content-Type: application/json' -d '{"email":"[email protected]","password":"your-password"}'

curl -X POST localhost:8055/auth/refresh -H 'Content-Type: application/json' -d '{"refresh_token": "W5L70MBXKElx5ZVZwxmQVG8qdVjukiRVIwD5FYG7tCPyyuCM_I3IyCsYnFhMUrRi", "mode": "json"}'

directus-mysql-template's People

Contributors

davekobrenski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.