Skip to content

Commit 74ce3be

Browse files
committed
chore: update wrangler conf structure
1 parent 7a3d71f commit 74ce3be

File tree

7 files changed

+22
-103
lines changed

7 files changed

+22
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
target/
22
build/
3+
pkg/
34

45
.DS_Store
56
.vscode/

build.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "bytes-radar",
33
"version": "1.0.0",
44
"description": "Cloudflare Worker for Bytes Radar",
5-
"main": "worker.ts",
65
"scripts": {
76
"build": "node build.js",
87
"dev": "wrangler dev",
@@ -16,4 +15,4 @@
1615
"typescript": "^5.3.3",
1716
"wrangler": "^3.28.1"
1817
}
19-
}
18+
}

server/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const { execSync } = require('child_process');
22
const fs = require('fs');
33
const path = require('path');
44

5-
if (!fs.existsSync('pkg')) {
6-
fs.mkdirSync('pkg');
5+
if (!fs.existsSync('server/pkg')) {
6+
fs.mkdirSync('server/pkg');
77
}
88

99
console.log('Building WebAssembly module...');

server/worker.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ export class BytesRadar {
3535
message,
3636
...(data && { data })
3737
};
38-
39-
console.log(`[${level.toUpperCase()}] ${message}`, data ? data : '');
38+
39+
const fn = {
40+
debug: console.debug,
41+
info: console.info,
42+
warn: console.warn,
43+
error: console.error,
44+
}
4045

4146
if (environment === 'production') {
42-
console.log(JSON.stringify(logEntry));
47+
fn[level](JSON.stringify(logEntry));
48+
} else {
49+
fn[level](`[${level.toUpperCase()}] ${message}`, data ? data : '');
4350
}
4451
}
4552
}
@@ -61,6 +68,11 @@ export class BytesRadar {
6168
}
6269

6370
async fetch(request: Request) {
71+
const url = new URL(request.url);
72+
if (url.pathname === '/favicon.ico') {
73+
return new Response(null, { status: 404 });
74+
}
75+
6476
const startTime = performance.now();
6577
const debugInfo: any = {
6678
timestamp: new Date().toISOString(),
@@ -71,7 +83,6 @@ export class BytesRadar {
7183
await this.initializeWasm();
7284
debugInfo.wasm_initialized = true;
7385

74-
const url = new URL(request.url);
7586
const pathParts = url.pathname.split('/').filter(Boolean);
7687
const targetUrl = pathParts.join('/');
7788

@@ -124,15 +135,7 @@ export class BytesRadar {
124135
debug_info: debugInfo
125136
};
126137

127-
console.log('Analysis completed successfully:', {
128-
url: targetUrl,
129-
project: debugInfo.project_name,
130-
files: debugInfo.files_analyzed,
131-
lines: debugInfo.total_lines,
132-
languages: debugInfo.languages_detected,
133-
size: debugInfo.total_size_formatted,
134-
duration: debugInfo.total_duration_ms + 'ms'
135-
});
138+
this.log('info', 'Analysis completed successfully', debugInfo);
136139

137140
return new Response(JSON.stringify(response), {
138141
headers: {
@@ -175,14 +178,7 @@ export class BytesRadar {
175178
debugInfo.suggested_fix = 'Please check the error details and try again';
176179
}
177180

178-
console.error('Error in BytesRadar fetch:', {
179-
error: errorMessage,
180-
type: errorType,
181-
category: debugInfo.error_category,
182-
stack: errorStack,
183-
url: debugInfo.target_url,
184-
duration: debugInfo.duration_ms + 'ms'
185-
});
181+
this.log('error', 'Error in BytesRadar fetch', debugInfo);
186182

187183
const errorResponse: any = {
188184
error: errorMessage,
@@ -201,14 +197,6 @@ export class BytesRadar {
201197
});
202198
}
203199
}
204-
205-
private formatBytes(bytes: number): string {
206-
if (bytes === 0) return '0 B';
207-
const k = 1024;
208-
const sizes = ['B', 'KB', 'MB', 'GB'];
209-
const i = Math.floor(Math.log(bytes) / Math.log(k));
210-
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
211-
}
212200
}
213201

214202
export default {

tsconfig.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main = "server/worker.ts"
33
compatibility_date = "2024-01-01"
44

55
[build]
6-
command = "node build.js"
6+
command = "node server/build.js"
77

88
[durable_objects]
99
bindings = [

0 commit comments

Comments
 (0)