Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: allow export of router #617

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -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
57 changes: 1 addition & 56 deletions index.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading