const base = process.argv[2] || process.env.SMOKE_BASE_URL || 'http://localhost:3070' const routes = [ '/admin', '/en', '/zh', '/en/products', '/zh/products', '/en/downloads', '/zh/downloads', '/en/news', '/zh/news', '/en/about', '/zh/about', '/en/contact', '/zh/contact', '/en/dealers', '/zh/dealers', '/en/dealers?tab=stores', '/zh/dealers?tab=stores', '/en/reviews', '/en/reviews?tab=reviews', '/zh/reviews', '/en/support', '/zh/support', '/en/support/contact', '/zh/support/contact', '/en/support/tutorial', '/zh/support/tutorial', '/api/health', '/favicon.ico', '/Product/index/model/DAC-Z10/target/X4C68nRijzjeq7k9e%5Bld%5D3ulg%3D%3D.html', ] async function check(route) { const url = new URL(route, base).toString() const response = await fetch(url, { redirect: 'manual' }) const location = response.headers.get('location') return { route, status: response.status, location, ok: response.status === 200 || (route.includes('/Product/index/model/') && response.status === 301 && Boolean(location)) || (route === '/' && response.status === 307 && Boolean(location)), } } const results = [] for (const route of routes) { results.push(await check(route)) } for (const result of results) { const suffix = result.location ? ` -> ${result.location}` : '' console.log(`${result.ok ? 'OK ' : 'BAD'} ${String(result.status).padEnd(3)} ${result.route}${suffix}`) } const failures = results.filter((result) => !result.ok) if (failures.length) { console.error(`\nSmoke check failed for ${failures.length} route(s).`) process.exit(1) } console.log(`\nSmoke check passed for ${results.length} route(s) against ${base}`)