X
This commit is contained in:
parent
225ff45b4f
commit
e5d43d1147
5 changed files with 1254 additions and 2 deletions
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
14
worker.js
14
worker.js
|
|
@ -65,6 +65,9 @@ export default {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const path = url.pathname;
|
const path = url.pathname;
|
||||||
|
|
||||||
|
console.log(`Received request for path: ${path}`);
|
||||||
|
console.log(`Full URL: ${url.toString()}`);
|
||||||
|
|
||||||
// Handle CORS preflight requests
|
// Handle CORS preflight requests
|
||||||
if (request.method === 'OPTIONS') {
|
if (request.method === 'OPTIONS') {
|
||||||
|
|
@ -78,6 +81,7 @@ export default {
|
||||||
|
|
||||||
// Handle static assets
|
// Handle static assets
|
||||||
if (path === '/styles.css' || path === '/index.html' || path === '/') {
|
if (path === '/styles.css' || path === '/index.html' || path === '/') {
|
||||||
|
console.log('Routing to static asset handler');
|
||||||
return serveStaticAsset(request, env);
|
return serveStaticAsset(request, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +160,7 @@ async function serveMedia(request, env) {
|
||||||
// Create response with appropriate headers
|
// Create response with appropriate headers
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.set('Content-Type', contentType);
|
headers.set('Content-Type', contentType);
|
||||||
headers.set('Cache-Control', 'public, max-age=31536000'); // 1 year cache
|
headers.set('Cache-Control', 'public, max-age=31536000'); // Cache for a year
|
||||||
headers.set('Access-Control-Allow-Origin', '*');
|
headers.set('Access-Control-Allow-Origin', '*');
|
||||||
|
|
||||||
return new Response(object.body, {
|
return new Response(object.body, {
|
||||||
|
|
@ -175,14 +179,18 @@ async function serveStaticAsset(request, env) {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const path = url.pathname;
|
const path = url.pathname;
|
||||||
|
|
||||||
|
console.log(`Attempting to serve static asset: ${path}`);
|
||||||
|
|
||||||
// Get the asset from the ASSETS binding
|
// Get the asset from the ASSETS binding
|
||||||
const asset = await env.ASSETS.get(path.substring(1));
|
const asset = await env.ASSETS.get(path.substring(1));
|
||||||
|
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
console.error(`Asset not found: ${path}`);
|
console.error(`Asset not found in bucket: ${path}`);
|
||||||
return new Response('Asset Not Found', { status: 404 });
|
return new Response('Asset Not Found', { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Asset found, size: ${asset.size} bytes`);
|
||||||
|
|
||||||
// Determine content type based on file extension
|
// Determine content type based on file extension
|
||||||
let contentType = 'text/plain';
|
let contentType = 'text/plain';
|
||||||
if (path.endsWith('.css')) {
|
if (path.endsWith('.css')) {
|
||||||
|
|
@ -193,6 +201,8 @@ async function serveStaticAsset(request, env) {
|
||||||
contentType = 'text/html';
|
contentType = 'text/html';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Content type set to: ${contentType}`);
|
||||||
|
|
||||||
// Create response with appropriate headers
|
// Create response with appropriate headers
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.set('Content-Type', contentType);
|
headers.set('Content-Type', contentType);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue