Skip to content

Commit 5c01858

Browse files
authored
Merge pull request #15 from techgeek03/master
Support context path for rendering static resources
2 parents 605e520 + 36d7a84 commit 5c01858

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,36 @@ spec:
145145
value: "80"
146146
```
147147
148+
## Cutomize URL context path
149+
150+
If you have an ingress that routes to a custom context path then you can customize the URL context path. The css files and the images will be loaded properly in that case.
151+
152+
```yaml
153+
apiVersion: apps/v1
154+
kind: Deployment
155+
metadata:
156+
name: hello-kubernetes-custom
157+
spec:
158+
replicas: 3
159+
selector:
160+
matchLabels:
161+
app: hello-kubernetes-custom
162+
template:
163+
metadata:
164+
labels:
165+
app: hello-kubernetes-custom
166+
spec:
167+
containers:
168+
- name: hello-kubernetes
169+
image: paulbouwer/hello-kubernetes:1.8
170+
ports:
171+
- containerPort: 8080
172+
env:
173+
- name: MESSAGE
174+
value: I just deployed this on Kubernetes!
175+
- name: CONTEXT_PATH
176+
value: "/api/v1/hello-kubernetes/"
177+
```
148178
149179
## Build Container Image
150180

app/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ app.use(morgan('combined'));
1212
// Configuration
1313
var port = process.env.PORT || 8080;
1414
var message = process.env.MESSAGE || "Hello world!";
15+
var contextPath = process.env.CONTEXT_PATH || "/";
1516

1617
app.get('/', function (req, res) {
1718
res.render('home', {
1819
message: message,
1920
platform: os.type(),
2021
release: os.release(),
21-
hostName: os.hostname()
22+
hostName: os.hostname(),
23+
contextPath: contextPath
2224
});
2325
});
2426

app/views/layouts/main.handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<html>
33
<head>
44
<title>Hello Kubernetes!</title>
5-
<link rel="stylesheet" type="text/css" href="/css/main.css">
5+
<link rel="stylesheet" type="text/css" href="{{ contextPath }}css/main.css">
66
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:300" >
77
</head>
88
<body>
99

1010
<div class="main">
11-
<img src="/images/kubernetes.png"/>
11+
<img src="{{ contextPath }}images/kubernetes.png"/>
1212
<div class="content">
1313
{{{body}}}
1414
</div>

0 commit comments

Comments
 (0)