Skip to content

Commit e8df55e

Browse files
committed
Support HTTPS
1 parent dff557a commit e8df55e

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Learning algorithms from text and static images is quite boring. For that, there have been many great websites that view animations of various algorithms. However, for us being coders, nothing can be more comprehensible than visualizing the actual working code. So here we introduce Algorithm Visualizer.
99

10-
[![Screenshot](https://raw.githubusercontent.com/algorithm-visualizer/algorithm-visualizer/master/branding/screenshot.png)](http://algorithm-visualizer.org/)
10+
[![Screenshot](https://raw.githubusercontent.com/algorithm-visualizer/algorithm-visualizer/master/branding/screenshot.png)](https://algorithm-visualizer.org/)
1111

1212
## Contributing
1313

app/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ const history = require('connect-history-api-fallback');
33
const express = require('express');
44
const app = express();
55

6+
const frontend = require('./frontend');
7+
const backend = require('./backend');
8+
69
const {
710
apiEndpoint,
11+
credentials,
812
} = require('../environment');
913

10-
const frontend = require('./frontend');
11-
const backend = require('./backend');
1214
app.use((req, res, next) => {
13-
if (req.hostname === 'algo-visualizer.jasonpark.me') return res.redirect(301, 'http://algorithm-visualizer.org/');
14-
next();
15+
if (req.hostname === 'algo-visualizer.jasonpark.me') {
16+
res.redirect(301, 'https://algorithm-visualizer.org/');
17+
} else if (credentials && !req.secure) {
18+
res.redirect(301, `https://${req.hostname}${req.url}`);
19+
} else {
20+
next();
21+
}
1522
});
1623
app.use(apiEndpoint, backend);
1724
app.use(history());

bin/www

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
#!/usr/bin/env node
22

33
const http = require('http');
4+
const https = require('https');
45

56
const app = require('../app');
67
const {
7-
port,
8+
httpPort,
9+
httpsPort,
10+
credentials,
811
} = require('../environment');
912

1013
const httpServer = http.createServer(app);
11-
httpServer.listen(port);
12-
console.info(`http: listening on port ${port}`);
14+
httpServer.listen(httpPort);
15+
console.info(`http: listening on port ${httpPort}`);
16+
17+
if (credentials) {
18+
const httpsServer = https.createServer(credentials, app);
19+
httpsServer.listen(httpsPort);
20+
console.info(`https: listening on port ${httpsPort}`);
21+
}

environment.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
const path = require('path');
2+
const fs = require('fs');
23

34
const {
45
NODE_ENV = 'production',
56

6-
PORT = '8080',
7+
HTTP_PORT = '8080',
8+
HTTPS_PORT = '8443',
79
PROXY_PORT = '3000',
810

911
GITHUB_CLIENT_ID,
1012
GITHUB_CLIENT_SECRET,
1113
GITHUB_WEBHOOK_SECRET,
14+
15+
CREDENTIALS_ENABLED = '0',
16+
CREDENTIALS_PATH,
17+
CREDENTIALS_CA,
18+
CREDENTIALS_KEY,
19+
CREDENTIALS_CERT,
1220
} = process.env;
1321

22+
const isEnabled = v => v === '1';
23+
1424
const __PROD__ = NODE_ENV === 'production';
1525
const __DEV__ = !__PROD__;
1626

17-
const port = parseInt(PORT);
27+
const httpPort = parseInt(HTTP_PORT);
28+
const httpsPort = parseInt(HTTPS_PORT);
1829
const proxyPort = parseInt(PROXY_PORT);
1930

2031
const githubClientId = GITHUB_CLIENT_ID;
2132
const githubClientSecret = GITHUB_CLIENT_SECRET;
2233
const githubWebhookSecret = GITHUB_WEBHOOK_SECRET;
2334

35+
const read = (file) => fs.readFileSync(path.resolve(CREDENTIALS_PATH, file));
36+
const credentials = isEnabled(CREDENTIALS_ENABLED) && {
37+
ca: read(CREDENTIALS_CA),
38+
key: read(CREDENTIALS_KEY),
39+
cert: read(CREDENTIALS_CERT),
40+
};
41+
2442
const buildPath = path.resolve(__dirname, 'build');
2543
const frontendBuildPath = path.resolve(buildPath, 'frontend');
2644
const backendBuildPath = path.resolve(buildPath, 'backend');
@@ -34,11 +52,13 @@ const apiEndpoint = '/api';
3452
module.exports = {
3553
__PROD__,
3654
__DEV__,
37-
port,
55+
httpPort,
56+
httpsPort,
3857
proxyPort,
3958
githubClientId,
4059
githubClientSecret,
4160
githubWebhookSecret,
61+
credentials,
4262
frontendBuildPath,
4363
backendBuildPath,
4464
frontendSrcPath,

src/backend/controllers/algorithms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ router.route('/sitemap.txt')
132132
.get((req, res, next) => {
133133
const urls = [];
134134
categories.forEach(category => category.algorithms.forEach(algorithm => {
135-
urls.push(`http://algorithm-visualizer.org/${category.key}/${algorithm.key}`);
135+
urls.push(`https://algorithm-visualizer.org/${category.key}/${algorithm.key}`);
136136
}));
137137
res.set('Content-Type', 'text/plain');
138138
res.send(urls.join('\n'));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy