From c87c1732ebe3f8869b1a6c1c87b0b513d83993e9 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 15:17:12 -0400 Subject: [PATCH 1/8] enable https on the backend --- backend/env.json | 13 +++++++++++++ backend/src/server.ts | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/backend/env.json b/backend/env.json index be4b1e9..caa3f31 100644 --- a/backend/env.json +++ b/backend/env.json @@ -30,6 +30,19 @@ "REMS_ADMIN_BASE" : { "type" : "string", "default" : "http://localhost:8090" +}, + +"HTTPS_KEY_PATH": { + "type": "string", + "default": "server.key" +}, +"HTTPS_CERT_PATH": { + "type": "string", + "default" : "server.cert" +}, +"USE_HTTPS": { + "type": "boolean", + "default": false } } diff --git a/backend/src/server.ts b/backend/src/server.ts index 219e92f..9d2e721 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -5,6 +5,8 @@ const app = express(); import cors from 'cors'; import mongoose from 'mongoose'; import env from 'var'; +import https from 'https'; +import fs from 'fs'; //middleware and configurations import bodyParser from 'body-parser'; @@ -20,9 +22,21 @@ async function main() { app.use(bodyParser.urlencoded({ extended: false })); app.use(cors(options)); - app.listen(port, () => console.log(`Listening on port ${port}`)); app.use('/doctorOrders', doctorOrders); + let server: any = app; + + if (env.USE_HTTPS) { + console.log("Enabling HTTPS HTTPS") + const credentials = { + key: fs.readFileSync(env.HTTPS_KEY_PATH), + cert: fs.readFileSync(env.HTTPS_CERT_PATH) + }; + server = https.createServer(credentials, app); + } + + server.listen(port, () => console.log(`Listening on port ${port}`)); + const mongoHost = env.MONGO_URL; await mongoose.connect(mongoHost, { From e7e4dfa58c3de92e0d06fc1f631e75da224a9d29 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 15:42:29 -0400 Subject: [PATCH 2/8] minor updates --- backend/src/server.ts | 2 +- frontend/env.json | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/src/server.ts b/backend/src/server.ts index 9d2e721..21f7360 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -27,7 +27,7 @@ async function main() { let server: any = app; if (env.USE_HTTPS) { - console.log("Enabling HTTPS HTTPS") + console.log("Enabling HTTPS HTTPS"); const credentials = { key: fs.readFileSync(env.HTTPS_KEY_PATH), cert: fs.readFileSync(env.HTTPS_CERT_PATH) diff --git a/frontend/env.json b/frontend/env.json index 0b41fae..6e17bef 100644 --- a/frontend/env.json +++ b/frontend/env.json @@ -5,7 +5,7 @@ }, "ALLOWED_ORIGIN" : { "type" : "object", - "default" : ["http://localhost:3000", "http://localhost:3000/", "http://localhost:3005", "http://localhost:3005/", "http://localhost:5050", "http://localhost:5050/", "http://localhost:4040", "http://localhost:4040/"] + "default" : ["http://localhost:3000", "https://localhost:3000/", "http://localhost:3005", "https://localhost:3005/", "http://localhost:5050", "https://localhost:5050/", "http://localhost:4040", "https://localhost:4040/"] }, "MONGO_USERNAME": { "type" : "string", @@ -35,6 +35,8 @@ "PORT" : { "type" :"number", "default" : 5050 -} +}, + + } From 57e38e4f2eb1ab6558e792e048dbca1cd51deb34 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 16:03:50 -0400 Subject: [PATCH 3/8] change double quotes to single --- backend/src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/server.ts b/backend/src/server.ts index 21f7360..99d7216 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -27,7 +27,7 @@ async function main() { let server: any = app; if (env.USE_HTTPS) { - console.log("Enabling HTTPS HTTPS"); + console.log('Enabling HTTPS HTTPS'); const credentials = { key: fs.readFileSync(env.HTTPS_KEY_PATH), cert: fs.readFileSync(env.HTTPS_CERT_PATH) From ad298da7392761cc54364cb27b71feb357671c18 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 16:11:33 -0400 Subject: [PATCH 4/8] fixed linting --- backend/test/simple.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/test/simple.test.ts b/backend/test/simple.test.ts index a0d0b80..b19a66b 100644 --- a/backend/test/simple.test.ts +++ b/backend/test/simple.test.ts @@ -1,4 +1,3 @@ -import router from '../src/routes/doctorOrders'; describe('help', () => { it.skip('should fail', () => { throw 'Errrrr'; From c4f122091e31e4111c614a1965ca0a1cef87e5e8 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 16:20:27 -0400 Subject: [PATCH 5/8] prettier linting --- backend/.eslintrc | 9 ++-- backend/.mocharc.json | 6 +-- backend/.prettierrc | 2 +- backend/env.json | 92 ++++++++++++++++++++++----------------- backend/package-lock.json | 2 +- backend/package.json | 2 +- backend/src/server.ts | 2 +- backend/tsconfig.json | 14 ++---- 8 files changed, 64 insertions(+), 65 deletions(-) diff --git a/backend/.eslintrc b/backend/.eslintrc index 5d540f2..64fe830 100644 --- a/backend/.eslintrc +++ b/backend/.eslintrc @@ -1,9 +1,6 @@ { "parser": "@typescript-eslint/parser", - "extends": [ - "plugin:@typescript-eslint/recommended", - "prettier" - ], + "extends": ["plugin:@typescript-eslint/recommended", "prettier"], "parserOptions": { "ecmaVersion": 2018, "sourceType": "module" @@ -14,6 +11,6 @@ "@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-explicit-any": "off" } -} \ No newline at end of file +} diff --git a/backend/.mocharc.json b/backend/.mocharc.json index 281531f..c4f8f00 100644 --- a/backend/.mocharc.json +++ b/backend/.mocharc.json @@ -1,7 +1,7 @@ { - "timeout" : 20000, + "timeout": 20000, "extension": ["ts"], "spec": "test/**/*.test.ts", "require": "ts-node/register", - "file" : ["test/setup.ts"] -} \ No newline at end of file + "file": ["test/setup.ts"] +} diff --git a/backend/.prettierrc b/backend/.prettierrc index 912f7bb..0243ce1 100644 --- a/backend/.prettierrc +++ b/backend/.prettierrc @@ -5,4 +5,4 @@ "printWidth": 100, "tabWidth": 2, "singleQuote": true -} \ No newline at end of file +} diff --git a/backend/env.json b/backend/env.json index caa3f31..0838ff2 100644 --- a/backend/env.json +++ b/backend/env.json @@ -1,48 +1,58 @@ { -"BACKEND_PORT" : { - "type" :"number", - "default" : 5051 -}, -"ALLOWED_ORIGIN" : { - "type" : "object", - "default" : ["http://localhost:3000", "http://localhost:3000/", "http://localhost:3005", "http://localhost:3005/", "http://localhost:3008", "http://localhost:3008/", "http://localhost:5050", "http://localhost:5050/", "http://localhost:4040", "http://localhost:4040/"] -}, -"MONGO_USERNAME": { - "type" : "string", - "default" : "rems-admin-pims-root" -}, + "BACKEND_PORT": { + "type": "number", + "default": 5051 + }, + "ALLOWED_ORIGIN": { + "type": "object", + "default": [ + "http://localhost:3000", + "http://localhost:3000/", + "http://localhost:3005", + "http://localhost:3005/", + "http://localhost:3008", + "http://localhost:3008/", + "http://localhost:5050", + "http://localhost:5050/", + "http://localhost:4040", + "http://localhost:4040/" + ] + }, + "MONGO_USERNAME": { + "type": "string", + "default": "rems-admin-pims-root" + }, -"MONGO_PASSWORD" :{ - "type" : "string", - "default" : "rems-admin-pims-password" -}, + "MONGO_PASSWORD": { + "type": "string", + "default": "rems-admin-pims-password" + }, -"MONGO_URL" : { - "type" : "string", - "default" : "mongodb://localhost:27017/pims" -}, + "MONGO_URL": { + "type": "string", + "default": "mongodb://localhost:27017/pims" + }, -"AUTH_SOURCE" :{ - "type" : "string", - "default" : "admin" -}, + "AUTH_SOURCE": { + "type": "string", + "default": "admin" + }, -"REMS_ADMIN_BASE" : { - "type" : "string", - "default" : "http://localhost:8090" -}, - -"HTTPS_KEY_PATH": { - "type": "string", - "default": "server.key" -}, -"HTTPS_CERT_PATH": { - "type": "string", - "default" : "server.cert" -}, -"USE_HTTPS": { - "type": "boolean", - "default": false -} + "REMS_ADMIN_BASE": { + "type": "string", + "default": "http://localhost:8090" + }, + "HTTPS_KEY_PATH": { + "type": "string", + "default": "server.key" + }, + "HTTPS_CERT_PATH": { + "type": "string", + "default": "server.cert" + }, + "USE_HTTPS": { + "type": "boolean", + "default": false + } } diff --git a/backend/package-lock.json b/backend/package-lock.json index f6cb779..918ac47 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -46,7 +46,7 @@ "mongodb-memory-server": "^8.12.1", "nock": "^13.2.9", "nodemon": "^2.0.20", - "prettier": "^2.0.5", + "prettier": "2.8.8", "sinon": "^15.0.3", "ts-node": "^10.9.1", "ts-node-dev": "^2.0.0", diff --git a/backend/package.json b/backend/package.json index bd9a52e..6983804 100644 --- a/backend/package.json +++ b/backend/package.json @@ -41,7 +41,7 @@ "mongodb-memory-server": "^8.12.1", "nock": "^13.2.9", "nodemon": "^2.0.20", - "prettier": "^2.0.5", + "prettier": "2.8.8", "sinon": "^15.0.3", "ts-node": "^10.9.1", "ts-node-dev": "^2.0.0", diff --git a/backend/src/server.ts b/backend/src/server.ts index 99d7216..118dcce 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -33,7 +33,7 @@ async function main() { cert: fs.readFileSync(env.HTTPS_CERT_PATH) }; server = https.createServer(credentials, app); - } + } server.listen(port, () => console.log(`Listening on port ${port}`)); diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 2c2bc1e..e548762 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -1,11 +1,7 @@ { "compilerOptions": { "target": "es6", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, @@ -20,12 +16,8 @@ "outDir": "dist", "jsx": "react-jsx", "paths": { - "*": [ - "./src/typings/*" - ] + "*": ["./src/typings/*"] } }, - "include": [ - "src" - ] + "include": ["src"] } From 02992723a5c2ca9ea3130079a7db47f6b47007c8 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 16:26:49 -0400 Subject: [PATCH 6/8] SO MUCH LINTING --- backend/test/simple.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/test/simple.test.ts b/backend/test/simple.test.ts index b19a66b..7b1de11 100644 --- a/backend/test/simple.test.ts +++ b/backend/test/simple.test.ts @@ -1,3 +1,5 @@ +import router from '../src/routes/doctorOrders'; + describe('help', () => { it.skip('should fail', () => { throw 'Errrrr'; From d893d556b374e46e555e917b6088fa015e5971be Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 17:19:14 -0400 Subject: [PATCH 7/8] cert files in frontend + gitignore --- .gitignore | 7 +++++++ frontend/env.json | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.gitignore b/.gitignore index a6aaa58..91b4877 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,10 @@ dist npm-debug.log* yarn-debug.log* yarn-error.log* + + +frontend/server.key +frontend/server.cert + +backend/server.key +backend/server.cert \ No newline at end of file diff --git a/frontend/env.json b/frontend/env.json index 6e17bef..84c66ad 100644 --- a/frontend/env.json +++ b/frontend/env.json @@ -37,6 +37,19 @@ "default" : 5050 }, +"SSL_KEY_FILE": { + "type": "string", + "default": "server.key" +}, +"SSL_CRT_FILE": { + "type": "string", + "default": "server.cert" +}, +"USE_HTTPS": { + "type": "boolean", + "default": false +} + } From 6bf8598528d113e7e1c8594e879aa29774fa428f Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Fri, 28 Jul 2023 17:20:27 -0400 Subject: [PATCH 8/8] remove white spaces --- frontend/env.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/env.json b/frontend/env.json index 84c66ad..3101dfa 100644 --- a/frontend/env.json +++ b/frontend/env.json @@ -49,7 +49,4 @@ "type": "boolean", "default": false } - - - }