Support HTTPS
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
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.
|
||||
|
||||
[](http://algorithm-visualizer.org/)
|
||||
[](https://algorithm-visualizer.org/)
|
||||
|
||||
## Contributing
|
||||
|
||||
|
||||
19
app/index.js
19
app/index.js
@@ -3,15 +3,22 @@ const history = require('connect-history-api-fallback');
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
const {
|
||||
apiEndpoint,
|
||||
} = require('../environment');
|
||||
|
||||
const frontend = require('./frontend');
|
||||
const backend = require('./backend');
|
||||
|
||||
const {
|
||||
apiEndpoint,
|
||||
credentials,
|
||||
} = require('../environment');
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (req.hostname === 'algo-visualizer.jasonpark.me') return res.redirect(301, 'http://algorithm-visualizer.org/');
|
||||
next();
|
||||
if (req.hostname === 'algo-visualizer.jasonpark.me') {
|
||||
res.redirect(301, 'https://algorithm-visualizer.org/');
|
||||
} else if (credentials && !req.secure) {
|
||||
res.redirect(301, `https://${req.hostname}${req.url}`);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
app.use(apiEndpoint, backend);
|
||||
app.use(history());
|
||||
|
||||
15
bin/www
15
bin/www
@@ -1,12 +1,21 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
|
||||
const app = require('../app');
|
||||
const {
|
||||
port,
|
||||
httpPort,
|
||||
httpsPort,
|
||||
credentials,
|
||||
} = require('../environment');
|
||||
|
||||
const httpServer = http.createServer(app);
|
||||
httpServer.listen(port);
|
||||
console.info(`http: listening on port ${port}`);
|
||||
httpServer.listen(httpPort);
|
||||
console.info(`http: listening on port ${httpPort}`);
|
||||
|
||||
if (credentials) {
|
||||
const httpsServer = https.createServer(credentials, app);
|
||||
httpsServer.listen(httpsPort);
|
||||
console.info(`https: listening on port ${httpsPort}`);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,44 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const {
|
||||
NODE_ENV = 'production',
|
||||
|
||||
PORT = '8080',
|
||||
HTTP_PORT = '8080',
|
||||
HTTPS_PORT = '8443',
|
||||
PROXY_PORT = '3000',
|
||||
|
||||
GITHUB_CLIENT_ID,
|
||||
GITHUB_CLIENT_SECRET,
|
||||
GITHUB_WEBHOOK_SECRET,
|
||||
|
||||
CREDENTIALS_ENABLED = '0',
|
||||
CREDENTIALS_PATH,
|
||||
CREDENTIALS_CA,
|
||||
CREDENTIALS_KEY,
|
||||
CREDENTIALS_CERT,
|
||||
} = process.env;
|
||||
|
||||
const isEnabled = v => v === '1';
|
||||
|
||||
const __PROD__ = NODE_ENV === 'production';
|
||||
const __DEV__ = !__PROD__;
|
||||
|
||||
const port = parseInt(PORT);
|
||||
const httpPort = parseInt(HTTP_PORT);
|
||||
const httpsPort = parseInt(HTTPS_PORT);
|
||||
const proxyPort = parseInt(PROXY_PORT);
|
||||
|
||||
const githubClientId = GITHUB_CLIENT_ID;
|
||||
const githubClientSecret = GITHUB_CLIENT_SECRET;
|
||||
const githubWebhookSecret = GITHUB_WEBHOOK_SECRET;
|
||||
|
||||
const read = (file) => fs.readFileSync(path.resolve(CREDENTIALS_PATH, file));
|
||||
const credentials = isEnabled(CREDENTIALS_ENABLED) && {
|
||||
ca: read(CREDENTIALS_CA),
|
||||
key: read(CREDENTIALS_KEY),
|
||||
cert: read(CREDENTIALS_CERT),
|
||||
};
|
||||
|
||||
const buildPath = path.resolve(__dirname, 'build');
|
||||
const frontendBuildPath = path.resolve(buildPath, 'frontend');
|
||||
const backendBuildPath = path.resolve(buildPath, 'backend');
|
||||
@@ -34,11 +52,13 @@ const apiEndpoint = '/api';
|
||||
module.exports = {
|
||||
__PROD__,
|
||||
__DEV__,
|
||||
port,
|
||||
httpPort,
|
||||
httpsPort,
|
||||
proxyPort,
|
||||
githubClientId,
|
||||
githubClientSecret,
|
||||
githubWebhookSecret,
|
||||
credentials,
|
||||
frontendBuildPath,
|
||||
backendBuildPath,
|
||||
frontendSrcPath,
|
||||
|
||||
@@ -132,7 +132,7 @@ router.route('/sitemap.txt')
|
||||
.get((req, res, next) => {
|
||||
const urls = [];
|
||||
categories.forEach(category => category.algorithms.forEach(algorithm => {
|
||||
urls.push(`http://algorithm-visualizer.org/${category.key}/${algorithm.key}`);
|
||||
urls.push(`https://algorithm-visualizer.org/${category.key}/${algorithm.key}`);
|
||||
}));
|
||||
res.set('Content-Type', 'text/plain');
|
||||
res.send(urls.join('\n'));
|
||||
|
||||
Reference in New Issue
Block a user