32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
const fs = require('fs');
|
|||
|
|
const content = fs.readFileSync('routes/auth.js', 'utf8');
|
||
|
|
|
||
|
|
// 修复路由路径:移除/api/auth前缀,因为主文件中已经使用了app.use('/api/auth', authRoutes)
|
||
|
|
const fixedContent = content
|
||
|
|
.replace(/router\.post\('\/api\/auth\/login'/g, "router.post('/login'")
|
||
|
|
.replace(/router\.get\('\/api\/auth\/verify'/g, "router.get('/verify'")
|
||
|
|
.replace(/router\.post\('\/api\/auth\/logout'/g, "router.post('/logout'");
|
||
|
|
|
||
|
|
// 写入修复后的文件
|
||
|
|
fs.writeFileSync('routes/auth.js', fixedContent);
|
||
|
|
console.log('✅ 已修复auth路由路径');
|
||
|
|
|
||
|
|
// 验证修复
|
||
|
|
const fixedFileContent = fs.readFileSync('routes/auth.js', 'utf8');
|
||
|
|
if (fixedFileContent.includes("router.post('/login'") &&
|
||
|
|
fixedFileContent.includes("router.get('/verify'") &&
|
||
|
|
fixedFileContent.includes("router.post('/logout'")) {
|
||
|
|
console.log('✅ 路径修复验证成功');
|
||
|
|
|
||
|
|
// 显示修复后的相关行
|
||
|
|
const lines = fixedFileContent.split('\n');
|
||
|
|
console.log('\n修复后的路由定义:');
|
||
|
|
for (let i = 0; i < lines.length; i++) {
|
||
|
|
if (lines[i].includes("router.")) {
|
||
|
|
console.log(`${i + 1}: ${lines[i]}`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
console.log('❌ 路径修复验证失败');
|
||
|
|
process.exit(1);
|
||
|
|
}
|