Remove https related code (and let AWS handle it)

master
Jinseo Park 4 years ago
parent 0d6dec45c3
commit b29024172c

@ -1,2 +1 @@
HTTP_PORT = 8080
HTTPS_PORT = 8443

@ -1,2 +1 @@
CREDENTIALS_ENABLED = 0
WEBHOOK_ENABLED = 0

@ -1,6 +1 @@
CREDENTIALS_ENABLED = 1
CREDENTIALS_PATH = /home/ubuntu/.certbot/config/live/algorithm-visualizer.org
CREDENTIALS_CA = fullchain.pem
CREDENTIALS_KEY = privkey.pem
CREDENTIALS_CERT = cert.pem
WEBHOOK_ENABLED = 1

@ -1,7 +0,0 @@
config-dir = /home/ubuntu/.certbot/config
work-dir = /home/ubuntu/.certbot/work
logs-dir = /home/ubuntu/.certbot/logs
email = jason.park@gatech.edu
authenticator = webroot
webroot-path = /home/ubuntu/server/public/frontend-built
domains = algorithm-visualizer.org

2026
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -4,9 +4,8 @@ import bodyParser from 'body-parser';
import * as Controllers from 'controllers';
import { NotFound } from 'ts-httpexceptions';
import compression from 'compression';
import { __PROD__, credentials, httpPort, httpsPort, webhookOptions } from 'config/environments';
import { __PROD__, httpPort, webhookOptions } from 'config/environments';
import http from 'http';
import https from 'https';
import { Hierarchy } from 'models';
import * as Tracers from 'tracers';
import { errorHandlerMiddleware, frontendMiddleware, redirectMiddleware } from 'middlewares';
@ -101,11 +100,5 @@ export default class Server {
const httpServer = http.createServer(this.app);
httpServer.listen(httpPort);
console.info(`http: listening on port ${httpPort}`);
if (credentials) {
const httpsServer = https.createServer(credentials, this.app);
httpsServer.listen(httpsPort);
console.info(`https: listening on port ${httpsPort}`);
}
}
}

@ -1,22 +1,9 @@
import fs from 'fs';
import { ServerOptions } from 'https';
import path from 'path';
import { spawn } from 'child_process';
import { rootDir } from 'config/paths';
require('dotenv-flow').config();
const {
NODE_ENV,
HTTP_PORT,
HTTPS_PORT,
CREDENTIALS_ENABLED,
CREDENTIALS_PATH,
CREDENTIALS_CA,
CREDENTIALS_KEY,
CREDENTIALS_CERT,
WEBHOOK_ENABLED,
WEBHOOK_SECRET,
@ -35,14 +22,6 @@ const isEnabled = (v: string) => v === '1';
const missingVars = [
'NODE_ENV',
'HTTP_PORT',
'HTTPS_PORT',
'CREDENTIALS_ENABLED',
...(isEnabled(CREDENTIALS_ENABLED) ? [
'CREDENTIALS_PATH',
'CREDENTIALS_CA',
'CREDENTIALS_KEY',
'CREDENTIALS_CERT',
] : []),
'WEBHOOK_ENABLED',
...(isEnabled(WEBHOOK_ENABLED) ? [
'WEBHOOK_SECRET',
@ -58,38 +37,12 @@ export const __PROD__ = NODE_ENV === 'production';
export const __DEV__ = NODE_ENV === 'development';
export const httpPort = parseInt(HTTP_PORT);
export const httpsPort = parseInt(HTTPS_PORT);
export const webhookOptions = isEnabled(WEBHOOK_ENABLED) ? {
path: '/webhook',
secret: WEBHOOK_SECRET,
} : undefined;
export let credentials: ServerOptions | undefined;
if (isEnabled(CREDENTIALS_ENABLED)) {
if (fs.existsSync(CREDENTIALS_PATH)) {
const readCredentials = (file: string) => fs.readFileSync(path.resolve(CREDENTIALS_PATH, file));
credentials = {
ca: readCredentials(CREDENTIALS_CA),
key: readCredentials(CREDENTIALS_KEY),
cert: readCredentials(CREDENTIALS_CERT),
};
} else {
const certbotIniPath = path.resolve(rootDir, 'certbot.ini');
const childProcess = spawn('certbot', ['certonly', '--non-interactive', '--agree-tos', '--config', certbotIniPath]);
childProcess.stdout.pipe(process.stdout);
childProcess.stderr.pipe(process.stderr);
childProcess.on('error', console.error);
childProcess.on('exit', code => {
if (code === 0) {
process.exit(0);
} else {
console.error(new Error(`certbot failed with exit code ${code}.`));
}
});
}
}
export const githubClientId = GITHUB_CLIENT_ID;
export const githubClientSecret = GITHUB_CLIENT_SECRET;

@ -1,12 +1,9 @@
import { NextFunction, Request, Response } from 'express';
import { credentials } from 'config/environments';
export function redirectMiddleware() {
return (req: Request, res: Response, next: NextFunction) => {
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();
}

Loading…
Cancel
Save