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/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 be4b1e9..0838ff2 100644 --- a/backend/env.json +++ b/backend/env.json @@ -1,35 +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" -} + "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 7020e67..cdc3031 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 5a0c30b..05c4cb8 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 219e92f..118dcce 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, { diff --git a/backend/test/simple.test.ts b/backend/test/simple.test.ts index a0d0b80..7b1de11 100644 --- a/backend/test/simple.test.ts +++ b/backend/test/simple.test.ts @@ -1,4 +1,5 @@ import router from '../src/routes/doctorOrders'; + describe('help', () => { it.skip('should fail', () => { throw 'Errrrr'; 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"] } diff --git a/frontend/env.json b/frontend/env.json index 0b41fae..3101dfa 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,18 @@ "PORT" : { "type" :"number", "default" : 5050 -} +}, +"SSL_KEY_FILE": { + "type": "string", + "default": "server.key" +}, +"SSL_CRT_FILE": { + "type": "string", + "default": "server.cert" +}, +"USE_HTTPS": { + "type": "boolean", + "default": false +} }