forked from unimatrix/web
Integrate live CHOAM exchange browser and protected read-only API
This commit is contained in:
parent
7876f2410e
commit
85c54ab3c6
1 changed files with 2 additions and 1 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import {handleFeed} from './feed-api.mjs';
|
||||
import {handleExchange} from './exchange-api.mjs';
|
||||
import {handleForum} from './forum-api.mjs';
|
||||
import {handleCommunity} from './community-api.mjs';
|
||||
import {handlePortal} from './portal-api.mjs';
|
||||
// ASSET_DATA is injected by scripts/build.mjs. No credentials enter this bundle.
|
||||
const security={'X-Content-Type-Options':'nosniff','Referrer-Policy':'strict-origin-when-cross-origin','Content-Security-Policy':"default-src 'self'; img-src 'self' data:; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; script-src 'self'; connect-src 'self'; frame-ancestors 'self' https://chatgpt.com https://*.chatgpt.com; base-uri 'self'; object-src 'none'"};
|
||||
export default {async fetch(request,env){const url=new URL(request.url);if(url.pathname==='/api/community')return handleCommunity(request);if(url.pathname==='/api/profile'||url.pathname.startsWith('/api/portal/')||url.pathname.startsWith('/api/tickets'))return handlePortal(request,env);if(url.pathname.startsWith('/api/forum'))return handleForum(request,env);if(url.pathname.startsWith('/api/'))return handleFeed(request,env);if(!['GET','HEAD'].includes(request.method))return new Response('Method not allowed',{status:405});let key;try{key=decodeURIComponent(url.pathname)}catch{return new Response('Bad request',{status:400})}if(key==='/')key='/index.html';const asset=ASSET_DATA[key];if(!asset)return new Response('Page not found',{status:404,headers:security});const [mime,b64]=asset;const data=request.method==='HEAD'?null:Uint8Array.from(atob(b64),c=>c.charCodeAt(0));return new Response(data,{headers:{...security,'Content-Type':mime,'Cache-Control':key.startsWith('/assets/')?'public, max-age=86400':'no-cache'}})}};
|
||||
export default {async fetch(request,env){const url=new URL(request.url);if(url.pathname.startsWith('/api/exchange/'))return handleExchange(request,env);if(url.pathname==='/api/community')return handleCommunity(request);if(url.pathname==='/api/profile'||url.pathname.startsWith('/api/portal/')||url.pathname.startsWith('/api/tickets'))return handlePortal(request,env);if(url.pathname.startsWith('/api/forum'))return handleForum(request,env);if(url.pathname.startsWith('/api/'))return handleFeed(request,env);if(!['GET','HEAD'].includes(request.method))return new Response('Method not allowed',{status:405});let key;try{key=decodeURIComponent(url.pathname)}catch{return new Response('Bad request',{status:400})}if(key==='/')key='/index.html';const asset=ASSET_DATA[key];if(!asset)return new Response('Page not found',{status:404,headers:security});const [mime,b64]=asset;const data=request.method==='HEAD'?null:Uint8Array.from(atob(b64),c=>c.charCodeAt(0));return new Response(data,{headers:{...security,'Content-Type':mime,'Cache-Control':key.startsWith('/assets/')?'public, max-age=86400':'no-cache'}})}};
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff