forked from netliferesearch/starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (29 loc) · 924 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* This is the setup for the staging and production server,
i.e not for development.
*/
/* eslint-disable */
const express = require('express');
const basicAuth = require('basic-auth');
const app = express();
const port = process.env.PORT || 3000;
// Authenticator
app.use((req, res, next) => {
const user = basicAuth(req);
const username = process.env.AUTH_USER || 'netlife';
const password = process.env.AUTH_PASS || 'research';
function unauthorized() {
res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
return res.sendStatus(401);
}
if (!user || !user.name || !user.pass) {
return unauthorized();
}
if (user.name === username && user.pass === password) {
return next();
}
return unauthorized();
});
app.use(express.static('dist'));
app.listen(port, () => {
console.log(`Open http://localhost:${port}/ 🚀`);
});