fix(ims): restore 100% real-time direct IMS scraping and fix Vite proxy Location header rewrite for VPS
Some checks failed
Deploy RIT Freshers Hub to VPS / Deploy to Live VPS (push) Has been cancelled

This commit is contained in:
Shanmuga Krishnan S M
2026-08-24 10:49:57 +05:30
parent f8047b6cd3
commit 8c7a3d7f1a
2 changed files with 20 additions and 210 deletions

View File

@@ -87,25 +87,24 @@ export default defineConfig({
secure: false,
configure: (proxy) => {
proxy.on('proxyRes', (proxyRes) => {
// Rewrite Location header to keep redirects through local proxy
// Rewrite Location header to keep redirects through local / VPS proxy
const location = proxyRes.headers['location'];
if (location) {
let rewritten = location;
if (rewritten.includes('ims.ritchennai.edu.in')) {
rewritten = rewritten.replace(/https?:\/\/ims\.ritchennai\.edu\.in/gi, 'http://localhost:5173/ims');
} else if (rewritten.startsWith('/')) {
rewritten = rewritten.replace(/https?:\/\/ims\.ritchennai\.edu\.in/gi, '/ims');
} else if (rewritten.startsWith('/') && !rewritten.startsWith('/ims')) {
rewritten = '/ims' + rewritten;
}
proxyRes.headers['location'] = rewritten;
}
// Tweak cookies for localhost
// Strip domain from cookies so session cookies bind to current host (localhost or VPS domain)
const setCookie = proxyRes.headers['set-cookie'];
if (setCookie) {
proxyRes.headers['set-cookie'] = (Array.isArray(setCookie) ? setCookie : [setCookie]).map((cookie: string) =>
cookie
.replace(/Secure/gi, '')
.replace(/samesite=none/gi, 'SameSite=Lax')
.replace(/domain=[^;]+/gi, '')
.replace(/path=[^;]+/gi, 'Path=/')
);
}
});