SR
Click to open github profile
Get Started

Configuration

Learn how to configure the Craft Query API Craft CMS plugin.


Note

If you're using a reverse proxy (with some Nginx magic) and serve both frontend and backend from the same domain, you usually don't need to configure these things. You can see an example of this setup in the craft-nuxt starter repository.

Configure Cors Origins

To prevent CORS origin errors in your frontend, you should configure allowed origins in the config/app.web.php file. Add the following configuration to define which domains are allowed to make cross-origin requests:

<?php

  return [
      'as corsFilter' => [
          'class' => \craft\filters\Cors::class,

          // Add your origins here
          'cors' => [
              'Origin' => [
                  'http://localhost:3000',
              ],
              'Access-Control-Request-Method' => ['GET'],
              'Access-Control-Request-Headers' => ['*'],
              'Access-Control-Allow-Credentials' => true,
              'Access-Control-Max-Age' => 86400,
              'Access-Control-Expose-Headers' => [],
          ],
      ],
  ];

Headless Mode

Set headless mode in your config/general.php to true.

Note

Read more about the headless mode.

Enable Preview

To enable previewing entries etc. you have to tell Craft CMS, where the frontend lives.

Add a new env var:

.env
WEBSITE_URL="http://localhost:3000"

Add new alias to Craft CMS:

Now add this recently created env var to your config/general.php as an alias.

config/general.php
->aliases([
    '@websiteUrl' => getenv('WEBSITE_URL'),
])

Change Site URL

And finally go to your control panel settings -> sites -> and change the base URL of your Site. If you click on the Craft CMS logo in the left top corner, you should land on your defined WEBSITE_URL


Copyright © 2025 Samuel Reichör