Skip to content

Commit ff44c7f

Browse files
committed
Update basic auth middleware for staging server, update k8 config
1 parent d1cc16d commit ff44c7f

File tree

2 files changed

+41
-53
lines changed

2 files changed

+41
-53
lines changed

kubernetes_app.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,17 @@ metadata:
127127
labels:
128128
name: staging
129129
---
130-
apiVersion: networking.k8s.io/v1beta1
130+
apiVersion: extensions/v1beta1
131131
kind: Ingress
132132
metadata:
133133
name: staging-editor-ingress-with-auth
134134
namespace: staging
135135
annotations:
136-
kubernetes.io/ingress.class: nginx
137-
# type of authentication
138-
nginx.ingress.kubernetes.io/auth-type: basic
139-
# name of the secret that contains the user/password definitions
140-
nginx.ingress.kubernetes.io/auth-secret: basic-auth
141-
# message to display with an appropriate context why the authentication is required
142-
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - p5.js Web Editor Staging'
143-
# kubernetes.io/ingress.global-static-ip-name: "web-editor-staging-ip"
136+
kubernetes.io/ingress.class: gce
137+
kubernetes.io/ingress.global-static-ip-name: "web-editor-staging-ip"
144138
spec:
145-
rules:
146-
- host: stagingeditor.p5js.org
147-
http:
148-
paths:
149-
- path: /
150-
backend:
151-
serviceName: web-editor-node
152-
servicePort: 8001
139+
serviceName: web-editor-node
140+
servicePort: 8001
153141
---
154142
apiVersion: v1
155143
kind: Service

server/server.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ const MongoStore = connectMongo(session);
3737

3838
app.get('/health', (req, res) => res.json({ success: true }));
3939

40-
// For basic auth, in setting up beta editor
41-
if (process.env.BASIC_USERNAME && process.env.BASIC_PASSWORD) {
42-
app.use(basicAuth({
43-
users: {
44-
[process.env.BASIC_USERNAME]: process.env.BASIC_PASSWORD
45-
},
46-
challenge: true
47-
}));
48-
}
49-
5040
const allowedCorsOrigins = [
5141
/p5js\.org$/,
5242
];
@@ -75,23 +65,6 @@ app.use(corsMiddleware);
7565
// Enable pre-flight OPTIONS route for all end-points
7666
app.options('*', corsMiddleware);
7767

78-
// Body parser, cookie parser, sessions, serve public assets
79-
app.use(
80-
'/locales',
81-
Express.static(
82-
path.resolve(__dirname, '../dist/static/locales'),
83-
{
84-
// Browsers must revalidate for changes to the locale files
85-
// It doesn't actually mean "don't cache this file"
86-
// See: https://jakearchibald.com/2016/caching-best-practices/
87-
setHeaders: res => res.setHeader('Cache-Control', 'no-cache')
88-
}
89-
)
90-
);
91-
app.use(Express.static(path.resolve(__dirname, '../dist/static'), {
92-
maxAge: process.env.STATIC_MAX_AGE || (process.env.NODE_ENV === 'production' ? '1d' : '0')
93-
}));
94-
9568
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
9669
app.use(bodyParser.json({ limit: '50mb' }));
9770
app.use(cookieParser());
@@ -111,16 +84,7 @@ app.use(session({
11184
})
11285
}));
11386

114-
app.use(passport.initialize());
115-
app.use(passport.session());
11687
app.use('/api/v1', requestsOfTypeJSON(), api);
117-
app.use('/editor', requestsOfTypeJSON(), users);
118-
app.use('/editor', requestsOfTypeJSON(), sessions);
119-
app.use('/editor', requestsOfTypeJSON(), files);
120-
app.use('/editor', requestsOfTypeJSON(), projects);
121-
app.use('/editor', requestsOfTypeJSON(), aws);
122-
app.use('/editor', requestsOfTypeJSON(), collections);
123-
12488
// This is a temporary way to test access via Personal Access Tokens
12589
// Sending a valid username:<personal-access-token> combination will
12690
// return the user's information.
@@ -129,6 +93,42 @@ app.get(
12993
passport.authenticate('basic', { session: false }), (req, res) => res.json(req.user)
13094
);
13195

96+
// For basic auth, but can't have double basic auth for API
97+
if (process.env.BASIC_USERNAME && process.env.BASIC_PASSWORD) {
98+
app.use(basicAuth({
99+
users: {
100+
[process.env.BASIC_USERNAME]: process.env.BASIC_PASSWORD
101+
},
102+
challenge: true
103+
}));
104+
}
105+
106+
// Body parser, cookie parser, sessions, serve public assets
107+
app.use(
108+
'/locales',
109+
Express.static(
110+
path.resolve(__dirname, '../dist/static/locales'),
111+
{
112+
// Browsers must revalidate for changes to the locale files
113+
// It doesn't actually mean "don't cache this file"
114+
// See: https://jakearchibald.com/2016/caching-best-practices/
115+
setHeaders: res => res.setHeader('Cache-Control', 'no-cache')
116+
}
117+
)
118+
);
119+
app.use(Express.static(path.resolve(__dirname, '../dist/static'), {
120+
maxAge: process.env.STATIC_MAX_AGE || (process.env.NODE_ENV === 'production' ? '1d' : '0')
121+
}));
122+
123+
app.use(passport.initialize());
124+
app.use(passport.session());
125+
app.use('/editor', requestsOfTypeJSON(), users);
126+
app.use('/editor', requestsOfTypeJSON(), sessions);
127+
app.use('/editor', requestsOfTypeJSON(), files);
128+
app.use('/editor', requestsOfTypeJSON(), projects);
129+
app.use('/editor', requestsOfTypeJSON(), aws);
130+
app.use('/editor', requestsOfTypeJSON(), collections);
131+
132132
// this is supposed to be TEMPORARY -- until i figure out
133133
// isomorphic rendering
134134
app.use('/', serverRoutes);

0 commit comments

Comments
 (0)