Skip to content

Commit 4831cbc

Browse files
committed
frontend rewrite fix
1 parent 0aba108 commit 4831cbc

3 files changed

Lines changed: 29 additions & 47 deletions

File tree

frontend-service/server.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ dotenv.config();
88

99
const app = express();
1010
const PORT = process.env.PORT || 3007;
11+
const HOST = process.env.HOST || '0.0.0.0';
1112

1213
// Configure base path from environment or use '/frontend' as default
13-
const BASE_PATH = process.env.BASE_PATH || '';
14+
const BASE_PATH = process.env.BASE_PATH || '/frontend';
1415

1516
app.set('view engine', 'ejs');
1617
app.set('views', path.join(__dirname, 'views'));
@@ -24,25 +25,25 @@ app.use(session({
2425
saveUninitialized: true,
2526
}));
2627

27-
// Health check at root path for Kubernetes probes
28-
app.get('/health', (req, res) => {
28+
// Unified health check
29+
app.get(`${BASE_PATH}/health`, (req, res) => {
2930
res.json({
3031
status: 'UP',
3132
details: 'Frontend service healthy'
3233
});
3334
});
3435

35-
// Root redirect - now using BASE_PATH
36+
// Root redirect
3637
app.get('/', (req, res) => {
3738
res.redirect(`${BASE_PATH}/login`);
3839
});
3940

40-
// Show login page
41+
// Login page
4142
app.get(`${BASE_PATH}/login`, (req, res) => {
4243
res.render('login', { error: null });
4344
});
4445

45-
// Submit login form
46+
// Login submit
4647
app.post(`${BASE_PATH}/login`, async (req, res) => {
4748
const { username, password } = req.body;
4849

@@ -60,7 +61,7 @@ app.post(`${BASE_PATH}/login`, async (req, res) => {
6061
}
6162
});
6263

63-
// Protected dashboard
64+
// Dashboard
6465
app.get(`${BASE_PATH}/dashboard`, async (req, res) => {
6566
if (!req.session.token) return res.redirect(`${BASE_PATH}/login`);
6667

@@ -80,15 +81,6 @@ app.get(`${BASE_PATH}/dashboard`, async (req, res) => {
8081
}
8182
});
8283

83-
// Additional health check at prefixed path for backward compatibility
84-
app.get(`${BASE_PATH}/health`, (req, res) => {
85-
res.json({
86-
status: 'UP',
87-
details: 'Frontend service healthy'
88-
});
84+
app.listen(PORT, HOST, () => {
85+
console.log(`Frontend running on http://${HOST}:${PORT}${BASE_PATH}`);
8986
});
90-
91-
app.listen(PORT, () => {
92-
console.log(`Frontend running on port ${PORT}`);
93-
console.log(`Using base path: '${BASE_PATH}'`);
94-
});

k8s/frontend/deployment.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,34 @@ spec:
2121
- name: frontend-service
2222
image: wizfi/frontend-service:latest
2323
ports:
24-
- containerPort: 3007
24+
- containerPort: 3007
2525
env:
2626
- name: PORT
2727
value: "3007"
2828
- name: HOST
2929
value: "0.0.0.0"
30-
- name: BASE_PATH # Added to match server.js configuration
30+
- name: BASE_PATH
3131
value: "/frontend"
3232
- name: JWT_SECRET
3333
valueFrom:
3434
secretKeyRef:
3535
name: jwt-secret
3636
key: JWT_SECRET
3737
- name: AUTH_SERVICE_URL
38-
value: "http://auth-service:3000"
38+
value: "https://wizfiservices.duckdns.org/auth"
3939
- name: ADMIN_SERVICE_URL
40-
value: "http://admin-service:3006"
40+
value: "https://wizfiservices.duckdns.org/admin"
4141
livenessProbe:
4242
httpGet:
43-
path: /health # Changed to use root health endpoint
43+
path: /frontend/health
4444
port: 3007
4545
initialDelaySeconds: 30
4646
periodSeconds: 10
4747
timeoutSeconds: 5
4848
failureThreshold: 3
4949
readinessProbe:
5050
httpGet:
51-
path: /health # Changed to use root health endpoint
51+
path: /frontend/health
5252
port: 3007
5353
initialDelaySeconds: 5
5454
periodSeconds: 5
@@ -59,11 +59,11 @@ spec:
5959
memory: "512Mi"
6060
cpu: "500m"
6161
limits:
62-
memory: "1Gi" # Increased limit for stability
62+
memory: "1Gi"
6363
cpu: "1000m"
6464
volumeMounts:
6565
- name: static-assets
6666
mountPath: /app/public
6767
volumes:
6868
- name: static-assets
69-
emptyDir: {}
69+
emptyDir: {}

wizfi-ingress.yaml

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,32 @@ metadata:
66
annotations:
77
cert-manager.io/cluster-issuer: letsencrypt-http
88
nginx.ingress.kubernetes.io/app-root: /frontend/login
9-
# Remove all rewrite rules and use exact path matching
10-
nginx.ingress.kubernetes.io/rewrite-target: /$2
11-
# Simplified configuration without snippets
129
nginx.ingress.kubernetes.io/use-regex: "true"
1310
spec:
1411
ingressClassName: nginx
1512
rules:
1613
- host: wizfiservices.duckdns.org
1714
http:
1815
paths:
19-
# Frontend paths - exact matches
20-
- path: /frontend/login
21-
pathType: Exact
22-
backend:
23-
service:
24-
name: frontend-service
25-
port:
26-
number: 80
27-
- path: /frontend/health
28-
pathType: Exact
29-
backend:
30-
service:
31-
name: frontend-service
32-
port:
33-
number: 80
16+
# Frontend paths - keep /frontend in request
3417
- path: /frontend
3518
pathType: Prefix
3619
backend:
3720
service:
3821
name: frontend-service
3922
port:
4023
number: 80
41-
# Other service paths
24+
25+
# Auth
4226
- path: /auth(/|$)(.*)
4327
pathType: Prefix
4428
backend:
4529
service:
4630
name: auth-service
4731
port:
4832
number: 3000
49-
33+
34+
# User
5035
- path: /user(/|$)(.*)
5136
pathType: Prefix
5237
backend:
@@ -55,6 +40,7 @@ spec:
5540
port:
5641
number: 3001
5742

43+
# Billing
5844
- path: /billing(/|$)(.*)
5945
pathType: Prefix
6046
backend:
@@ -63,6 +49,7 @@ spec:
6349
port:
6450
number: 3002
6551

52+
# Payments
6653
- path: /payments(/|$)(.*)
6754
pathType: Prefix
6855
backend:
@@ -71,6 +58,7 @@ spec:
7158
port:
7259
number: 3003
7360

61+
# Notifications
7462
- path: /notify(/|$)(.*)
7563
pathType: Prefix
7664
backend:
@@ -79,6 +67,7 @@ spec:
7967
port:
8068
number: 3004
8169

70+
# Analytics
8271
- path: /analytics(/|$)(.*)
8372
pathType: Prefix
8473
backend:
@@ -87,6 +76,7 @@ spec:
8776
port:
8877
number: 3005
8978

79+
# Admin
9080
- path: /admin(/|$)(.*)
9181
pathType: Prefix
9282
backend:
@@ -98,4 +88,4 @@ spec:
9888
tls:
9989
- hosts:
10090
- wizfiservices.duckdns.org
101-
secretName: wizfi-tls
91+
secretName: wizfi-tls

0 commit comments

Comments
 (0)