8 lines
1.9 KiB
JavaScript
8 lines
1.9 KiB
JavaScript
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'; frame-src https://cp.dunerealms.com https://shop.dunerealms.com; 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.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'}})}};
|

Staff