MCPcopy Create free account
hub / github.com/decaporg/decap-cms / ProxyBackend

Class ProxyBackend

packages/decap-cms-backend-proxy/src/implementation.ts:75–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75export default class ProxyBackend implements Implementation {
76 proxyUrl: string;
77 mediaFolder: string;
78 options: { initialWorkflowStatus?: string };
79 branch: string;
80 cmsLabelPrefix?: string;
81
82 constructor(config: Config, options = {}) {
83 if (!config.backend.proxy_url) {
84 throw new Error('The Proxy backend needs a "proxy_url" in the backend configuration.');
85 }
86
87 const normalizedProxyUrl = normalizeProxyUrl(config.backend.proxy_url);
88
89 if (!normalizedProxyUrl) {
90 throw new Error('The Proxy backend requires an http(s) or root-relative "proxy_url".');
91 }
92
93 this.branch = config.backend.branch || 'master';
94 this.proxyUrl = normalizedProxyUrl;
95 this.mediaFolder = config.media_folder;
96 this.options = options;
97 this.cmsLabelPrefix = config.backend.cms_label_prefix;
98 }
99
100 isGitBackend() {
101 return false;
102 }
103
104 status() {
105 return Promise.resolve({ auth: { status: true }, api: { status: true, statusPage: '' } });
106 }
107
108 authComponent() {
109 return AuthenticationPage;
110 }
111
112 restoreUser() {
113 return this.authenticate();
114 }
115
116 authenticate() {
117 return Promise.resolve() as unknown as Promise<User>;
118 }
119
120 logout() {
121 return null;
122 }
123
124 getToken() {
125 return Promise.resolve('');
126 }
127
128 async request(payload: { action: string; params: Record<string, unknown> }) {
129 const response = await unsentRequest.fetchWithTimeout(this.proxyUrl, {
130 method: 'POST',
131 headers: { 'Content-Type': 'application/json; charset=utf-8' },
132 body: JSON.stringify({ branch: this.branch, ...payload }),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected