(request: Request)
| 118 | port, |
| 119 | hostname: '0.0.0.0', |
| 120 | async fetch(request: Request) { |
| 121 | const url = new URL(request.url); |
| 122 | |
| 123 | if (url.pathname === '/health') { |
| 124 | return new Response('ok', { |
| 125 | headers: { |
| 126 | 'Content-Type': 'text/plain; charset=utf-8', |
| 127 | 'Cache-Control': 'no-store', |
| 128 | }, |
| 129 | }); |
| 130 | } |
| 131 | |
| 132 | if (url.pathname.startsWith('/checkUpdate/')) { |
| 133 | if (request.method !== 'POST') { |
| 134 | return new Response('method not allowed', { status: 405 }); |
| 135 | } |
| 136 | |
| 137 | const appKey = url.pathname.split('/').pop(); |
| 138 | const platform = appKey ? appKeyToPlatform[appKey] : null; |
| 139 | if (!platform) { |
| 140 | return json({ message: 'unknown appKey' }, 404); |
| 141 | } |
| 142 | |
| 143 | const payload = (await request |
| 144 | .json() |
| 145 | .catch(() => ({}))) as { hash?: unknown }; |
| 146 | const currentHash = typeof payload.hash === 'string' ? payload.hash : ''; |
| 147 | |
| 148 | return json(buildUpdateResponse(platform, currentHash, url.origin)); |
| 149 | } |
| 150 | |
| 151 | if (url.pathname.startsWith('/artifacts/')) { |
| 152 | const filePath = safeResolve(url.pathname); |
| 153 | if ( |
| 154 | !filePath || |
| 155 | !fs.existsSync(filePath) || |
| 156 | fs.statSync(filePath).isDirectory() |
| 157 | ) { |
| 158 | return new Response('not found', { status: 404 }); |
| 159 | } |
| 160 | |
| 161 | const file = Bun.file(filePath); |
| 162 | const ext = path.extname(filePath); |
| 163 | const contentType = contentTypes[ext] || 'application/octet-stream'; |
| 164 | |
| 165 | return new Response(request.method === 'HEAD' ? null : file, { |
| 166 | headers: { |
| 167 | 'Content-Type': contentType, |
| 168 | 'Content-Length': String(file.size), |
| 169 | 'Cache-Control': 'no-store', |
| 170 | }, |
| 171 | }); |
| 172 | } |
| 173 | |
| 174 | return new Response('not found', { status: 404 }); |
| 175 | }, |
| 176 | }); |
| 177 |
no test coverage detected