diff --git a/.husky/pre-push b/.husky/pre-push index b0d13d4..0473f6c 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npx commitlint --from origin/master --to HEAD --verbose +npx commitlint --from origin/main --to HEAD --verbose diff --git a/app.js b/app.js new file mode 100755 index 0000000..86d8918 --- /dev/null +++ b/app.js @@ -0,0 +1,59 @@ +#!/usr/bin/env node +const fs = require('fs') +const express = require('express') +const morgan = require('morgan') +const path = require('path') +require('dotenv').config() + +const { + configOIDC, + configOIDCv2, + configMyInfo, + configSGID, +} = require('./lib/express') + +const serviceProvider = { + cert: fs.readFileSync( + path.resolve( + __dirname, + process.env.SERVICE_PROVIDER_CERT_PATH || './static/certs/server.crt', + ), + ), + pubKey: fs.readFileSync( + path.resolve( + __dirname, + process.env.SERVICE_PROVIDER_PUB_KEY || './static/certs/key.pub', + ), + ), +} + +const cryptoConfig = { + signAssertion: process.env.SIGN_ASSERTION !== 'false', // default to true to be backward compatable + signResponse: process.env.SIGN_RESPONSE !== 'false', + encryptAssertion: process.env.ENCRYPT_ASSERTION !== 'false', + resolveArtifactRequestSigned: + process.env.RESOLVE_ARTIFACT_REQUEST_SIGNED !== 'false', +} + +const options = { + serviceProvider, + showLoginPage: (req) => + (req.header('X-Show-Login-Page') || process.env.SHOW_LOGIN_PAGE) === 'true', + encryptMyInfo: process.env.ENCRYPT_MYINFO === 'true', + cryptoConfig, +} + +const app = express() +app.use(morgan('combined')) + +configOIDC(app, options) +configOIDCv2(app, options) +configSGID(app, options) + +configMyInfo.consent(app) +configMyInfo.v3(app, options) + +app.enable('trust proxy') +app.use(express.static(path.join(__dirname, 'public'))) + +exports.app = app diff --git a/index.js b/index.js index aff6d82..f7e50e3 100755 --- a/index.js +++ b/index.js @@ -1,63 +1,8 @@ #!/usr/bin/env node -const fs = require('fs') -const express = require('express') -const morgan = require('morgan') -const path = require('path') -require('dotenv').config() - -const { - configOIDC, - configOIDCv2, - configMyInfo, - configSGID, -} = require('./lib/express') +const { app } = require('./app') const PORT = process.env.MOCKPASS_PORT || process.env.PORT || 5156 -const serviceProvider = { - cert: fs.readFileSync( - path.resolve( - __dirname, - process.env.SERVICE_PROVIDER_CERT_PATH || './static/certs/server.crt', - ), - ), - pubKey: fs.readFileSync( - path.resolve( - __dirname, - process.env.SERVICE_PROVIDER_PUB_KEY || './static/certs/key.pub', - ), - ), -} - -const cryptoConfig = { - signAssertion: process.env.SIGN_ASSERTION !== 'false', // default to true to be backward compatable - signResponse: process.env.SIGN_RESPONSE !== 'false', - encryptAssertion: process.env.ENCRYPT_ASSERTION !== 'false', - resolveArtifactRequestSigned: - process.env.RESOLVE_ARTIFACT_REQUEST_SIGNED !== 'false', -} - -const options = { - serviceProvider, - showLoginPage: (req) => - (req.header('X-Show-Login-Page') || process.env.SHOW_LOGIN_PAGE) === 'true', - encryptMyInfo: process.env.ENCRYPT_MYINFO === 'true', - cryptoConfig, -} - -const app = express() -app.use(morgan('combined')) - -configOIDC(app, options) -configOIDCv2(app, options) -configSGID(app, options) - -configMyInfo.consent(app) -configMyInfo.v3(app, options) - -app.enable('trust proxy') -app.use(express.static(path.join(__dirname, 'public'))) - app.listen(PORT, (err) => err ? console.error('Unable to start MockPass', err) diff --git a/package.json b/package.json index ed68938..60d1546 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,13 @@ "name": "@opengovsg/mockpass", "version": "4.0.11", "description": "A mock SingPass/CorpPass server for dev purposes", - "main": "index.js", + "main": "app.js", "bin": { "mockpass": "index.js" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon", + "start": "nodemon index", "cz": "git-cz", "lint": "eslint lib", "lint-fix": "eslint --fix lib",