├── README.md ├── backend ├── .gitignore ├── .prettierrc ├── README.md ├── api │ ├── keys.js │ ├── namespaces.js │ └── values.js ├── cors-helper.js ├── dist │ └── worker.js ├── index.js ├── package.json ├── swagger.json └── wrangler.toml └── frontend ├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── App.test.js ├── index.css ├── index.js ├── logo.svg ├── reportWebVitals.js └── setupTests.js └── yarn.lock /README.md: -------------------------------------------------------------------------------- 1 | # Cloudflare CMS 2 | 3 | Link to Frontend: https://cloudflare-cms.pages.dev/ 4 | 5 | Link to Backend: https://cloudflare-cms-api.kevc.workers.dev/ 6 | 7 | Cloudflare CMS is a content management system that utilises Cloudflare Products (Workers, KV, and Pages) to provide a familiar UI environment to use Cloudflare Products. This Swagger UI page allows you to access your Cloudflare KV and use it like a NoSQL database. 'Values' are JSON arrays, 'Keys' are a collection of JSON arrays, and 'Namespaces' are like a collection of 'keys'. This Swagger page can be used to access Cloudflare KV belonging to any person, as long as you have the API token with KV permissions. 8 | 9 | Important Notes: 10 | 11 | * Authorize with your API token (Enter `Bearer ` in the Authorize prompt) 12 | * `accountId` can be found on the right side of your account's workers overview page 13 | * `namespaceId` can be found in your account's worker KV page 14 | * `keyName` is the name of the key in your namespace 15 | * `itemId` is the ID of an object in the array of values of the key 16 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | worker/ 3 | .cargo-ok 4 | package-lock.json 5 | -------------------------------------------------------------------------------- /backend/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 4, 4 | "semi": false, 5 | "singleQuote": true 6 | } 7 | -------------------------------------------------------------------------------- /backend/README.md: -------------------------------------------------------------------------------- 1 | ## Router 2 | 3 | This template demonstrates using the [`itty-router`](https://github.com/kwhitley/itty-router) package to add routing to your Cloudflare Workers. 4 | 5 | [`index.js`](https://github.com/cloudflare/worker-template-router/blob/master/index.js) is the content of the Workers script. 6 | 7 | #### Wrangler 8 | 9 | You can use [wrangler](https://github.com/cloudflare/wrangler) to generate a new Cloudflare Workers project based on this template by running the following command from your terminal: 10 | 11 | ``` 12 | wrangler generate myapp https://github.com/cloudflare/worker-template-router 13 | ``` 14 | 15 | Before publishing your code you need to edit `wrangler.toml` file and add your Cloudflare `account_id` - more information about configuring and publishing your code can be found [in the documentation](https://developers.cloudflare.com/workers/learning/getting-started#7-configure-your-project-for-deployment). 16 | 17 | Once you are ready, you can publish your code by running the following command: 18 | 19 | ``` 20 | wrangler publish 21 | ``` 22 | -------------------------------------------------------------------------------- /backend/api/keys.js: -------------------------------------------------------------------------------- 1 | const BASE_URL = 'https://api.cloudflare.com/client/v4/accounts/' 2 | const headers = { 3 | 'Access-Control-Allow-Origin': '*', 4 | 'Content-type': 'application/json', 5 | } 6 | export const getKeys = async request => { 7 | const accountId = request.params.accountId 8 | const namespaceId = request.params.namespaceId 9 | const apiKey = request.headers.get('Authorization') 10 | 11 | const resp = await fetch( 12 | `${BASE_URL + accountId}/storage/kv/namespaces/${namespaceId}/keys`, 13 | { 14 | headers: { 15 | Authorization: apiKey, 16 | }, 17 | } 18 | ).then(resp => resp.json()) 19 | return new Response(JSON.stringify(resp, null, 2), { headers }) 20 | } 21 | 22 | /* 23 | { 24 | "title": "My New Key" 25 | } 26 | */ 27 | export const postNewKey = async request => { 28 | const accountId = request.params.accountId 29 | const namespaceId = request.params.namespaceId 30 | const apiKey = request.headers.get('Authorization') 31 | const data = await request.json() 32 | const keyName = data['title'] 33 | const resp = await fetch( 34 | `${BASE_URL + 35 | accountId}/storage/kv/namespaces/${namespaceId}/values/${keyName}`, 36 | { 37 | method: 'PUT', 38 | headers: { 39 | Authorization: apiKey, 40 | 'Content-Type': 'text/plain', 41 | }, 42 | body: '[]', 43 | } 44 | ).then(resp => resp.json()) 45 | return new Response(JSON.stringify(resp, null, 2), { headers }) 46 | } 47 | -------------------------------------------------------------------------------- /backend/api/namespaces.js: -------------------------------------------------------------------------------- 1 | const BASE_URL = 'https://api.cloudflare.com/client/v4/accounts/' 2 | const headers = { 3 | 'Access-Control-Allow-Origin': '*', 4 | 'Content-type': 'application/json', 5 | } 6 | export const getNamespaces = async request => { 7 | const accountId = request.params.accountId 8 | const apiKey = request.headers.get('Authorization') 9 | 10 | const resp = await fetch(BASE_URL + accountId + '/storage/kv/namespaces', { 11 | headers: { 12 | Authorization: apiKey, 13 | }, 14 | }).then(resp => resp.json()) 15 | return new Response(JSON.stringify(resp, null, 2), { headers }) 16 | } 17 | 18 | /* 19 | { 20 | "title": "My Namespace" 21 | } 22 | */ 23 | export const postNamespaces = async request => { 24 | const accountId = request.params.accountId 25 | const data = await request.json() 26 | const apiKey = request.headers.get('Authorization') 27 | 28 | const resp = await fetch(BASE_URL + accountId + '/storage/kv/namespaces', { 29 | method: 'POST', 30 | headers: { 31 | Authorization: apiKey, 32 | 'Content-Type': 'application/json', 33 | }, 34 | body: JSON.stringify(data), 35 | }).then(resp => resp.json()) 36 | return new Response(JSON.stringify(resp, null, 2), { headers }) 37 | } 38 | 39 | /* 40 | { 41 | "title": "My Namespace" 42 | } 43 | */ 44 | export const putNamespaces = async request => { 45 | const accountId = request.params.accountId 46 | const namespaceId = request.params.namespaceId 47 | const apiKey = request.headers.get('Authorization') 48 | const data = await request.json() 49 | 50 | const resp = await fetch( 51 | BASE_URL + accountId + '/storage/kv/namespaces/' + namespaceId, 52 | { 53 | method: 'PUT', 54 | headers: { 55 | Authorization: apiKey, 56 | 'Content-Type': 'application/json', 57 | }, 58 | body: JSON.stringify(data), 59 | } 60 | ).then(resp => resp.json()) 61 | return new Response(JSON.stringify(resp, null, 2), { headers }) 62 | } 63 | 64 | export const deleteNamespaces = async request => { 65 | const accountId = request.params.accountId 66 | const namespaceId = request.params.namespaceId 67 | const apiKey = request.headers.get('Authorization') 68 | const resp = await fetch( 69 | BASE_URL + accountId + '/storage/kv/namespaces/' + namespaceId, 70 | { 71 | method: 'DELETE', 72 | headers: { 73 | Authorization: apiKey, 74 | }, 75 | } 76 | ).then(resp => resp.json()) 77 | return new Response(JSON.stringify(resp, null, 2), { headers }) 78 | } 79 | -------------------------------------------------------------------------------- /backend/api/values.js: -------------------------------------------------------------------------------- 1 | const BASE_URL = 'https://api.cloudflare.com/client/v4/accounts/' 2 | const headers = { 3 | 'Access-Control-Allow-Origin': '*', 4 | 'Content-type': 'application/json', 5 | } 6 | 7 | const getData = (apiKey, accountId, namespaceId, keyName) => { 8 | return fetch( 9 | `${BASE_URL + 10 | accountId}/storage/kv/namespaces/${namespaceId}/values/${keyName}`, 11 | { 12 | headers: { 13 | Authorization: apiKey, 14 | }, 15 | } 16 | ).then(resp => resp.json()) 17 | } 18 | 19 | const putData = (apiKey, accountId, namespaceId, keyName, toPut) => { 20 | return fetch( 21 | `${BASE_URL + 22 | accountId}/storage/kv/namespaces/${namespaceId}/values/${keyName}`, 23 | { 24 | method: 'PUT', 25 | headers: { 26 | Authorization: apiKey, 27 | 'Content-Type': 'text/plain', 28 | }, 29 | body: JSON.stringify(toPut), 30 | } 31 | ).then(resp => resp.json()) 32 | } 33 | 34 | export const getValues = async request => { 35 | const accountId = request.params.accountId 36 | const namespaceId = request.params.namespaceId 37 | const keyName = request.params.keyName 38 | const apiKey = request.headers.get('Authorization') 39 | 40 | const resp = await getData(apiKey, accountId, namespaceId, keyName) 41 | return new Response(JSON.stringify(resp, null, 2), { headers }) 42 | } 43 | 44 | export const postNewValue = async request => { 45 | const accountId = request.params.accountId 46 | const namespaceId = request.params.namespaceId 47 | const keyName = request.params.keyName 48 | const apiKey = request.headers.get('Authorization') 49 | const toAdd = await request.json() 50 | toAdd['id'] = crypto.randomUUID() 51 | const curr = await getData(apiKey, accountId, namespaceId, keyName) 52 | curr.push(toAdd) 53 | const resp = await putData(apiKey, accountId, namespaceId, keyName, curr) 54 | return new Response(JSON.stringify(resp, null, 2), { headers }) 55 | } 56 | 57 | export const getValue = async request => { 58 | const accountId = request.params.accountId 59 | const namespaceId = request.params.namespaceId 60 | const keyName = request.params.keyName 61 | const itemId = request.params.itemId 62 | const apiKey = request.headers.get('Authorization') 63 | const curr = await getData(apiKey, accountId, namespaceId, keyName) 64 | const item = curr.find(item => item['id'] === itemId) 65 | return new Response(JSON.stringify(item, null, 2), { headers }) 66 | } 67 | 68 | export const putValue = async request => { 69 | const accountId = request.params.accountId 70 | const namespaceId = request.params.namespaceId 71 | const keyName = request.params.keyName 72 | const itemId = request.params.itemId 73 | const apiKey = request.headers.get('Authorization') 74 | const toPut = await request.json() 75 | const curr = await getData(apiKey, accountId, namespaceId, keyName) 76 | const indexToPut = curr.findIndex(item => item['id'] === itemId) 77 | if (indexToPut >= 0) { 78 | curr[indexToPut] = toPut 79 | curr[indexToPut]['id'] = itemId 80 | } 81 | const resp = await putData(apiKey, accountId, namespaceId, keyName, curr) 82 | return new Response(JSON.stringify(resp, null, 2), { headers }) 83 | } 84 | 85 | export const deleteValue = async request => { 86 | const accountId = request.params.accountId 87 | const namespaceId = request.params.namespaceId 88 | const keyName = request.params.keyName 89 | const itemId = request.params.itemId 90 | const apiKey = request.headers.get('Authorization') 91 | const curr = await getData(apiKey, accountId, namespaceId, keyName) 92 | const indexToDelete = curr.findIndex(item => item['id'] === itemId) 93 | if (indexToDelete >= 0) { 94 | curr.splice(indexToDelete, 1) 95 | } 96 | console.log(curr) 97 | const resp = await putData(apiKey, accountId, namespaceId, keyName, curr) 98 | return new Response(JSON.stringify(resp, null, 2), { headers }) 99 | } 100 | -------------------------------------------------------------------------------- /backend/cors-helper.js: -------------------------------------------------------------------------------- 1 | export const corsHelper = request => { 2 | const corsHeaders = { 3 | 'Access-Control-Allow-Origin': '*', 4 | 'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS', 5 | 'Access-Control-Max-Age': '86400', 6 | } 7 | let headers = request.headers 8 | if ( 9 | headers.get('Origin') !== null && 10 | headers.get('Access-Control-Request-Method') !== null && 11 | headers.get('Access-Control-Request-Headers') !== null 12 | ) { 13 | // Handle CORS pre-flight request. 14 | // If you want to check or reject the requested method + headers 15 | // you can do that here. 16 | let respHeaders = { 17 | ...corsHeaders, 18 | // Allow all future content Request headers to go back to browser 19 | // such as Authorization (Bearer) or X-Client-Name-Version 20 | 'Access-Control-Allow-Headers': request.headers.get( 21 | 'Access-Control-Request-Headers' 22 | ), 23 | } 24 | 25 | return new Response(null, { 26 | headers: respHeaders, 27 | }) 28 | } else { 29 | // Handle standard OPTIONS request. 30 | // If you want to allow other HTTP Methods, you can do that here. 31 | return new Response(null, { 32 | headers: { 33 | Allow: 'GET,POST,PUT,DELETE,OPTIONS', 34 | }, 35 | }) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /backend/dist/worker.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function a(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,a),s.l=!0,s.exports}a.m=e,a.c=t,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)a.d(n,s,function(t){return e[t]}.bind(null,s));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=1)}([function(e,t){e.exports={Router:({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(a,n,s)=>(a,...o)=>t.push([n.toUpperCase(),RegExp(`^${(e+a).replace(/(\/?)\*/g,"($1.*)?").replace(/\/$/,"").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.")}/*$`),o])&&s}),routes:t,async handle(e,...a){let n,s,o=new URL(e.url);for(var[r,c,i]of(e.query=Object.fromEntries(o.searchParams),t))if((r===e.method||"ALL"===r)&&(s=o.pathname.match(c)))for(var d of(e.params=s.groups,i))if(void 0!==(n=await d(e.proxy||e,...a)))return n}})}},function(e,t,a){"use strict";a.r(t);var n=a(0);const s="https://api.cloudflare.com/client/v4/accounts/",o={"Access-Control-Allow-Origin":"*","Content-type":"application/json"},r="https://api.cloudflare.com/client/v4/accounts/",c={"Access-Control-Allow-Origin":"*","Content-type":"application/json"},i="https://api.cloudflare.com/client/v4/accounts/",d={"Access-Control-Allow-Origin":"*","Content-type":"application/json"},u=(e,t,a,n)=>fetch(`${i+t}/storage/kv/namespaces/${a}/values/${n}`,{headers:{Authorization:e}}).then(e=>e.json()),p=(e,t,a,n,s)=>fetch(`${i+t}/storage/kv/namespaces/${a}/values/${n}`,{method:"PUT",headers:{Authorization:e,"Content-Type":"text/plain"},body:JSON.stringify(s)}).then(e=>e.json()),l=Object(n.Router)();l.options("*",e=>{const t={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,POST,PUT,DELETE,OPTIONS","Access-Control-Max-Age":"86400"};let a=e.headers;if(null!==a.get("Origin")&&null!==a.get("Access-Control-Request-Method")&&null!==a.get("Access-Control-Request-Headers")){let a={...t,"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers")};return new Response(null,{headers:a})}return new Response(null,{headers:{Allow:"GET,POST,PUT,DELETE,OPTIONS"}})}),l.get("/:accountId",async e=>{const t=e.params.accountId,a=e.headers.get("Authorization"),n=await fetch(s+t+"/storage/kv/namespaces",{headers:{Authorization:a}}).then(e=>e.json());return new Response(JSON.stringify(n,null,2),{headers:o})}),l.post("/:accountId",async e=>{const t=e.params.accountId,a=await e.json(),n=e.headers.get("Authorization"),r=await fetch(s+t+"/storage/kv/namespaces",{method:"POST",headers:{Authorization:n,"Content-Type":"application/json"},body:JSON.stringify(a)}).then(e=>e.json());return new Response(JSON.stringify(r,null,2),{headers:o})}),l.put("/:accountId/:namespaceId",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.headers.get("Authorization"),r=await e.json(),c=await fetch(s+t+"/storage/kv/namespaces/"+a,{method:"PUT",headers:{Authorization:n,"Content-Type":"application/json"},body:JSON.stringify(r)}).then(e=>e.json());return new Response(JSON.stringify(c,null,2),{headers:o})}),l.delete("/:accountId/:namespaceId",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.headers.get("Authorization"),r=await fetch(s+t+"/storage/kv/namespaces/"+a,{method:"DELETE",headers:{Authorization:n}}).then(e=>e.json());return new Response(JSON.stringify(r,null,2),{headers:o})}),l.get("/:accountId/:namespaceId/keys",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.headers.get("Authorization"),s=await fetch(`${r+t}/storage/kv/namespaces/${a}/keys`,{headers:{Authorization:n}}).then(e=>e.json());return new Response(JSON.stringify(s,null,2),{headers:c})}),l.post("/:accountId/:namespaceId/keys",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.headers.get("Authorization"),s=(await e.json()).title,o=await fetch(`${r+t}/storage/kv/namespaces/${a}/values/${s}`,{method:"PUT",headers:{Authorization:n,"Content-Type":"text/plain"},body:"[]"}).then(e=>e.json());return new Response(JSON.stringify(o,null,2),{headers:c})}),l.get("/:accountId/:namespaceId/:keyName",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.params.keyName,s=e.headers.get("Authorization"),o=await u(s,t,a,n);return new Response(JSON.stringify(o,null,2),{headers:d})}),l.post("/:accountId/:namespaceId/:keyName",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.params.keyName,s=e.headers.get("Authorization"),o=await e.json();o.id=crypto.randomUUID();const r=await u(s,t,a,n);r.push(o);const c=await p(s,t,a,n,r);return new Response(JSON.stringify(c,null,2),{headers:d})}),l.get("/:accountId/:namespaceId/:keyName/:itemId",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.params.keyName,s=e.params.itemId,o=e.headers.get("Authorization"),r=(await u(o,t,a,n)).find(e=>e.id===s);return new Response(JSON.stringify(r,null,2),{headers:d})}),l.put("/:accountId/:namespaceId/:keyName/:itemId",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.params.keyName,s=e.params.itemId,o=e.headers.get("Authorization"),r=await e.json(),c=await u(o,t,a,n),i=c.findIndex(e=>e.id===s);i>=0&&(c[i]=r,c[i].id=s);const l=await p(o,t,a,n,c);return new Response(JSON.stringify(l,null,2),{headers:d})}),l.delete("/:accountId/:namespaceId/:keyName/:itemId",async e=>{const t=e.params.accountId,a=e.params.namespaceId,n=e.params.keyName,s=e.params.itemId,o=e.headers.get("Authorization"),r=await u(o,t,a,n),c=r.findIndex(e=>e.id===s);c>=0&&r.splice(c,1),console.log(r);const i=await p(o,t,a,n,r);return new Response(JSON.stringify(i,null,2),{headers:d})}),l.all("*",()=>new Response("404, not found!",{status:404})),addEventListener("fetch",e=>{e.respondWith(l.handle(e.request))})}]); -------------------------------------------------------------------------------- /backend/index.js: -------------------------------------------------------------------------------- 1 | import { Router } from 'itty-router' 2 | import { corsHelper } from './cors-helper' 3 | import { 4 | getNamespaces, 5 | postNamespaces, 6 | putNamespaces, 7 | deleteNamespaces, 8 | } from './api/namespaces' 9 | import { getKeys, postNewKey } from './api/keys' 10 | import { 11 | getValues, 12 | postNewValue, 13 | getValue, 14 | putValue, 15 | deleteValue, 16 | } from './api/values' 17 | 18 | const router = Router() 19 | 20 | router.options('*', corsHelper) 21 | 22 | router.get('/:accountId', getNamespaces) 23 | router.post('/:accountId', postNamespaces) 24 | router.put('/:accountId/:namespaceId', putNamespaces) 25 | router.delete('/:accountId/:namespaceId', deleteNamespaces) 26 | 27 | router.get('/:accountId/:namespaceId/keys', getKeys) 28 | router.post('/:accountId/:namespaceId/keys', postNewKey) 29 | 30 | router.get('/:accountId/:namespaceId/:keyName', getValues) 31 | router.post('/:accountId/:namespaceId/:keyName', postNewValue) 32 | 33 | router.get('/:accountId/:namespaceId/:keyName/:itemId', getValue) 34 | router.put('/:accountId/:namespaceId/:keyName/:itemId', putValue) 35 | router.delete('/:accountId/:namespaceId/:keyName/:itemId', deleteValue) 36 | 37 | router.all('*', () => new Response('404, not found!', { status: 404 })) 38 | 39 | addEventListener('fetch', e => { 40 | e.respondWith(router.handle(e.request)) 41 | }) 42 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "private": true, 4 | "version": "1.0.0", 5 | "description": "package for creating workers templates", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1", 9 | "format": "prettier --write '**/*.{js,css,json,md}'" 10 | }, 11 | "author": "thekevinconnor", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "prettier": "^1.17.0" 15 | }, 16 | "dependencies": { 17 | "itty-router": "^2.1.9", 18 | "itty-router-extras": "^0.4.2", 19 | "serverless-cloudflare-workers": "^1.2.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /backend/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "Cloudflare CMS is a content management system that utilises Cloudflare Products (Workers, KV, and Pages) to provide a familiar UI environment to use Cloudflare Products. This Swagger UI page allows you to access your Cloudflare KV and use it like a NoSQL database. 'Values' are JSON arrays, 'Keys' are a collection of JSON arrays, and 'Namespaces' are like a collection of 'keys'. This Swagger page can be used to access Cloudflare KV belonging to any person, as long as you have the API token with KV permissions.\n\nImportant Notes:\n* Authorize with your API token (Enter 'Bearer ' in the Authorize prompt)\n* `accountId` can be found on the right side of your account's workers overview page \n* `namespaceId` can be found in your account's worker KV page\n* `keyName` is the name of the key in your namespace\n* `itemId` is the ID of an object in the array of values of the key\n", 5 | "version": "1.0.0", 6 | "title": "Cloudflare CMS API" 7 | }, 8 | "host": "cloudflare-cms-api.kevc.workers.dev", 9 | "basePath": "/", 10 | "tags": [ 11 | { 12 | "name": "namespaces", 13 | "description": "Collection of keys" 14 | }, 15 | { 16 | "name": "keys", 17 | "description": "Collection of values" 18 | }, 19 | { 20 | "name": "values", 21 | "description": "JSON Arrays" 22 | } 23 | ], 24 | "schemes": [ 25 | "https" 26 | ], 27 | "paths": { 28 | "/{accountId}": { 29 | "parameters": [ 30 | { 31 | "$ref": "#/parameters/accountId" 32 | } 33 | ], 34 | "get": { 35 | "tags": [ 36 | "namespaces" 37 | ], 38 | "summary": "Get all namespaces", 39 | "consumes": [ 40 | "application/json" 41 | ], 42 | "produces": [ 43 | "application/json" 44 | ], 45 | "responses": { 46 | "200": { 47 | "description": "OK" 48 | } 49 | }, 50 | "security": [ 51 | { 52 | "api_key": [] 53 | } 54 | ] 55 | }, 56 | "post": { 57 | "tags": [ 58 | "namespaces" 59 | ], 60 | "summary": "Create new namespace", 61 | "consumes": [ 62 | "application/json" 63 | ], 64 | "produces": [ 65 | "application/json" 66 | ], 67 | "parameters": [ 68 | { 69 | "in": "body", 70 | "name": "payload", 71 | "description": "New namespace details", 72 | "required": true, 73 | "schema": { 74 | "$ref": "#/definitions/Namespace" 75 | } 76 | } 77 | ], 78 | "responses": { 79 | "200": { 80 | "description": "OK" 81 | } 82 | }, 83 | "security": [ 84 | { 85 | "api_key": [] 86 | } 87 | ] 88 | } 89 | }, 90 | "/{accountId}/{namespaceId}": { 91 | "parameters": [ 92 | { 93 | "$ref": "#/parameters/accountId" 94 | }, 95 | { 96 | "$ref": "#/parameters/namespaceId" 97 | } 98 | ], 99 | "put": { 100 | "tags": [ 101 | "namespaces" 102 | ], 103 | "summary": "Update namespace", 104 | "consumes": [ 105 | "application/json" 106 | ], 107 | "produces": [ 108 | "application/json" 109 | ], 110 | "parameters": [ 111 | { 112 | "in": "body", 113 | "name": "payload", 114 | "description": "Namespace update details", 115 | "required": true, 116 | "schema": { 117 | "$ref": "#/definitions/Namespace" 118 | } 119 | } 120 | ], 121 | "responses": { 122 | "200": { 123 | "description": "OK" 124 | } 125 | }, 126 | "security": [ 127 | { 128 | "api_key": [] 129 | } 130 | ] 131 | }, 132 | "delete": { 133 | "tags": [ 134 | "namespaces" 135 | ], 136 | "summary": "Delete namespaces", 137 | "consumes": [ 138 | "application/json" 139 | ], 140 | "produces": [ 141 | "application/json" 142 | ], 143 | "responses": { 144 | "200": { 145 | "description": "OK" 146 | } 147 | }, 148 | "security": [ 149 | { 150 | "api_key": [] 151 | } 152 | ] 153 | } 154 | }, 155 | "/{accountId}/{namespaceId}/keys": { 156 | "parameters": [ 157 | { 158 | "$ref": "#/parameters/accountId" 159 | }, 160 | { 161 | "$ref": "#/parameters/namespaceId" 162 | } 163 | ], 164 | "get": { 165 | "tags": [ 166 | "keys" 167 | ], 168 | "summary": "Get all keys", 169 | "consumes": [ 170 | "application/json" 171 | ], 172 | "produces": [ 173 | "application/json" 174 | ], 175 | "responses": { 176 | "200": { 177 | "description": "OK" 178 | } 179 | }, 180 | "security": [ 181 | { 182 | "api_key": [] 183 | } 184 | ] 185 | }, 186 | "post": { 187 | "tags": [ 188 | "keys" 189 | ], 190 | "summary": "Create new key", 191 | "consumes": [ 192 | "application/json" 193 | ], 194 | "produces": [ 195 | "application/json" 196 | ], 197 | "parameters": [ 198 | { 199 | "in": "body", 200 | "name": "payload", 201 | "description": "New key details", 202 | "required": true, 203 | "schema": { 204 | "$ref": "#/definitions/Key" 205 | } 206 | } 207 | ], 208 | "responses": { 209 | "200": { 210 | "description": "OK" 211 | } 212 | }, 213 | "security": [ 214 | { 215 | "api_key": [] 216 | } 217 | ] 218 | } 219 | }, 220 | "/{accountId}/{namespaceId}/{keyName}": { 221 | "parameters": [ 222 | { 223 | "$ref": "#/parameters/accountId" 224 | }, 225 | { 226 | "$ref": "#/parameters/namespaceId" 227 | }, 228 | { 229 | "$ref": "#/parameters/keyName" 230 | } 231 | ], 232 | "get": { 233 | "tags": [ 234 | "values" 235 | ], 236 | "summary": "Get all values in key", 237 | "consumes": [ 238 | "application/json" 239 | ], 240 | "produces": [ 241 | "application/json" 242 | ], 243 | "responses": { 244 | "200": { 245 | "description": "OK" 246 | } 247 | }, 248 | "security": [ 249 | { 250 | "api_key": [] 251 | } 252 | ] 253 | }, 254 | "post": { 255 | "tags": [ 256 | "values" 257 | ], 258 | "summary": "Add item to values", 259 | "consumes": [ 260 | "application/json" 261 | ], 262 | "produces": [ 263 | "application/json" 264 | ], 265 | "parameters": [ 266 | { 267 | "in": "body", 268 | "name": "payload", 269 | "description": "New item details", 270 | "required": true, 271 | "schema": { 272 | "$ref": "#/definitions/Value" 273 | } 274 | } 275 | ], 276 | "responses": { 277 | "200": { 278 | "description": "OK" 279 | } 280 | }, 281 | "security": [ 282 | { 283 | "api_key": [] 284 | } 285 | ] 286 | } 287 | }, 288 | "/{accountId}/{namespaceId}/{keyName}/{itemId}": { 289 | "parameters": [ 290 | { 291 | "$ref": "#/parameters/accountId" 292 | }, 293 | { 294 | "$ref": "#/parameters/namespaceId" 295 | }, 296 | { 297 | "$ref": "#/parameters/keyName" 298 | }, 299 | { 300 | "$ref": "#/parameters/itemId" 301 | } 302 | ], 303 | "get": { 304 | "tags": [ 305 | "values" 306 | ], 307 | "summary": "Get single item in values", 308 | "consumes": [ 309 | "application/json" 310 | ], 311 | "produces": [ 312 | "application/json" 313 | ], 314 | "responses": { 315 | "200": { 316 | "description": "OK" 317 | } 318 | }, 319 | "security": [ 320 | { 321 | "api_key": [] 322 | } 323 | ] 324 | }, 325 | "put": { 326 | "tags": [ 327 | "values" 328 | ], 329 | "summary": "Update single item in values", 330 | "consumes": [ 331 | "application/json" 332 | ], 333 | "produces": [ 334 | "application/json" 335 | ], 336 | "parameters": [ 337 | { 338 | "in": "body", 339 | "name": "payload", 340 | "description": "Value update details", 341 | "required": true, 342 | "schema": { 343 | "$ref": "#/definitions/Value" 344 | } 345 | } 346 | ], 347 | "responses": { 348 | "200": { 349 | "description": "OK" 350 | } 351 | }, 352 | "security": [ 353 | { 354 | "api_key": [] 355 | } 356 | ] 357 | }, 358 | "delete": { 359 | "tags": [ 360 | "values" 361 | ], 362 | "summary": "Delete single item in values", 363 | "consumes": [ 364 | "application/json" 365 | ], 366 | "produces": [ 367 | "application/json" 368 | ], 369 | "responses": { 370 | "200": { 371 | "description": "OK" 372 | } 373 | }, 374 | "security": [ 375 | { 376 | "api_key": [] 377 | } 378 | ] 379 | } 380 | } 381 | }, 382 | "securityDefinitions": { 383 | "api_key": { 384 | "type": "apiKey", 385 | "name": "Authorization", 386 | "in": "header", 387 | "description": "Bearer token (Cloudflare Token with KV permissions)" 388 | } 389 | }, 390 | "definitions": { 391 | "Namespace": { 392 | "type": "object", 393 | "properties": { 394 | "title": { 395 | "type": "string" 396 | } 397 | }, 398 | "xml": { 399 | "name": "Namespace" 400 | } 401 | }, 402 | "Key": { 403 | "type": "object", 404 | "properties": { 405 | "title": { 406 | "type": "string" 407 | } 408 | }, 409 | "xml": { 410 | "name": "Key" 411 | } 412 | }, 413 | "Value": { 414 | "type": "object", 415 | "properties": { 416 | "foo": { 417 | "type": "string" 418 | }, 419 | "bar": { 420 | "type": "integer" 421 | } 422 | }, 423 | "xml": { 424 | "name": "Value" 425 | } 426 | } 427 | }, 428 | "parameters": { 429 | "accountId": { 430 | "name": "accountId", 431 | "in": "path", 432 | "description": "ID of account", 433 | "required": true, 434 | "type": "string" 435 | }, 436 | "namespaceId": { 437 | "name": "namespaceId", 438 | "in": "path", 439 | "description": "ID of namespace", 440 | "required": true, 441 | "type": "string" 442 | }, 443 | "keyName": { 444 | "name": "keyName", 445 | "in": "path", 446 | "description": "Name of key", 447 | "required": true, 448 | "type": "string" 449 | }, 450 | "itemId": { 451 | "name": "itemId", 452 | "in": "path", 453 | "description": "ID of item", 454 | "required": true, 455 | "type": "string" 456 | } 457 | } 458 | } -------------------------------------------------------------------------------- /backend/wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "cloudflare-cms-api" 2 | type = "webpack" 3 | 4 | account_id = "f4faa25babf160d8f45bfc33444f4dee" 5 | workers_dev = true 6 | route = "cloudflare-cms.pages.dev/api" 7 | zone_id = "" 8 | compatibility_date = "2021-10-23" 9 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cloudflare-cms-frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "react": "^17.0.2", 10 | "react-dom": "^17.0.2", 11 | "react-scripts": "4.0.3", 12 | "swagger-ui-react": "^3.52.5", 13 | "web-vitals": "^1.0.1" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev-inc/cloudflare-cms/e87338579ee02ac7aee1cb0a21f5fa7e84e4114e/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | Cloudflare CMS Swagger UI 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev-inc/cloudflare-cms/e87338579ee02ac7aee1cb0a21f5fa7e84e4114e/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev-inc/cloudflare-cms/e87338579ee02ac7aee1cb0a21f5fa7e84e4114e/frontend/public/logo512.png -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import SwaggerUI from "swagger-ui-react"; 2 | import "swagger-ui-react/swagger-ui.css"; 3 | 4 | function App() { 5 | return ( 6 | 7 | ); 8 | } 9 | 10 | export default App; 11 | -------------------------------------------------------------------------------- /frontend/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /frontend/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /frontend/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | --------------------------------------------------------------------------------