Decap Proxy: Work With a Local Repository
You can connect Decap CMS to a local folder, instead of working with a live git repository.
- Navigate to a local directory configured with the CMS.
- Add the top-level property
local_backendconfiguration to yourconfig.yml:
# when using the default proxy server port
local_backend: true
backend:
name: git-gateway
- Run
npx decap-serverfrom the root directory of the above repository.
- If the default port (8081) is in use, the proxy server won’t start and you will see an error message. In this case, configure the port number.
Start your local development server (e.g. run
gatsby develop).Open
http://localhost:<port>/adminto verify that your can administer your content locally. Replace<port>with the port of your local development server. For example Gatsby’s default port is8000.
Limitation: editorial_workflow is not supported in this environment.
Options
By default, the proxy server runs on port 8081 and allows CORS requests from any origin. You can customize these settings with these options.
Environment Variables
PORTdefine the port you’d like the proxy server to use. RunningPORT=8082 npm run startstarts the server on port8082rather than the default8081.BIND_HOSTvariable allows binding to 127.0.0.1 rather than all IP addresses. RunningBIND_HOST=localhost npm run startallows connecting tohttp://localhost:8081/but connections tohttp://<public_ip>:8081/are no longer possible. 3.9ORIGINallows restricting CORS responses to a specific origin rather that allowing the API to be accessed from any server. RunningORIGIN=https://example.com npm run startchanges the HTTP header in responses toAccess-Content-Allow-Origin: https://example.com. The server can no longer be accessed by arbitrary websites. 3.9
You can define them in 2 ways:
- Create a
.envfile in the project’s root folder and add these optional variables:
PORT=8082
BIND_HOST=8082
ORIGIN=https://my-local-site.com
- Set these variables before the shell command, for example:
PORT=8082 npx decap-server
Custom Port and Host for the Backend URL
Update the local_backend object in config.yml and specify a url property to use your custom port number
backend:
name: git-gateway
local_backend:
# when using a custom proxy server port
url: http://localhost:8082/api/v1
# when accessing the local site from a host other than 'localhost' or '127.0.0.1'
allowed_hosts: ['192.168.0.1']