diff options
author | Nick Coutsos <[email protected]> | 2022-04-23 19:24:06 -0400 |
---|---|---|
committer | Nick Coutsos <[email protected]> | 2022-04-23 19:24:06 -0400 |
commit | 69b3829df59b96db40155dbdf5adbf549164a6be (patch) | |
tree | 1f1ea9a421730c98f75a84100cd18ffa96cdd8de | |
parent | 5fc92da78b10ab35ba57d28a0e1e2c547fa42e91 (diff) | |
download | keymap-editor-69b3829df59b96db40155dbdf5adbf549164a6be.tar.gz keymap-editor-69b3829df59b96db40155dbdf5adbf549164a6be.zip |
Fix missing config flags
-rw-r--r-- | api/config.js | 26 | ||||
-rw-r--r-- | api/index.js | 9 | ||||
-rw-r--r-- | api/routes/application.js | 6 | ||||
-rw-r--r-- | api/services/github/auth.js | 15 | ||||
-rw-r--r-- | application/components/keyboard-picker.vue | 2 | ||||
-rw-r--r-- | index.js | 7 |
6 files changed, 47 insertions, 18 deletions
diff --git a/api/config.js b/api/config.js new file mode 100644 index 0000000..ff9644f --- /dev/null +++ b/api/config.js @@ -0,0 +1,26 @@ +const process = require('process') +require('dotenv/config') + +const PORT = process.env.PORT || 8080 +const ENABLE_DEV_SERVER = process.env.ENABLE_DEV_SERVER +const ENABLE_GITHUB = process.env.ENABLE_GITHUB +const GITHUB_APP_NAME = process.env.GITHUB_APP_NAME +const GITHUB_APP_PRIVATE_KEY = process.env.GITHUB_APP_PRIVATE_KEY +const GITHUB_APP_ID = process.env.GITHUB_APP_ID +const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID +const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET +const GITHUB_OAUTH_CALLBACK_URL = process.env.GITHUB_OAUTH_CALLBACK_URL +const APP_BASE_URL = process.env.APP_BASE_URL + +module.exports = { + PORT, + ENABLE_DEV_SERVER, + ENABLE_GITHUB, + GITHUB_APP_NAME, + GITHUB_APP_PRIVATE_KEY, + GITHUB_APP_ID, + GITHUB_CLIENT_ID, + GITHUB_CLIENT_SECRET, + GITHUB_OAUTH_CALLBACK_URL, + APP_BASE_URL +} diff --git a/api/index.js b/api/index.js index d45471c..9c7e63c 100644 --- a/api/index.js +++ b/api/index.js @@ -1,9 +1,9 @@ -require('dotenv/config') const express = require('express') const bodyParser = require('body-parser') const cors = require('cors') const morgan = require('morgan') +const config = require('./config') const applicationInit = require('./routes/application') const keyboards = require('./routes/keyboards') @@ -14,14 +14,15 @@ app.use(cors({ origin: 'https://nickcoutsos.github.io' })) -if (process.env.ENABLE_DEV_SERVER) { +if (config.ENABLE_DEV_SERVER) { applicationInit(app) } app.use(morgan('dev')) -app.use(keyboards) -app.use('/github', require('./routes/github')) app.get('/health', (req, res) => res.sendStatus(200)) +app.use(keyboards) +config.ENABLE_GITHUB && app.use('/github', require('./routes/github')) + module.exports = app diff --git a/api/routes/application.js b/api/routes/application.js index 3ecac87..add60be 100644 --- a/api/routes/application.js +++ b/api/routes/application.js @@ -3,6 +3,8 @@ const path = require('path') const express = require('express') const expressWs = require('express-ws') +const config = require('../config') + const appDir = path.join(__dirname, '..', '..', 'application') function init (app) { @@ -12,8 +14,8 @@ function init (app) { cwd: appDir, env: Object.assign({}, process.env, { ENABLE_LOCAL: true, - ENABLE_GITHUB: true, - GITHUB_APP_NAME: process.env.GITHUB_APP_NAME, + ENABLE_GITHUB: config.ENABLE_GITHUB, + GITHUB_APP_NAME: config.GITHUB_APP_NAME, API_BASE_URL: 'http://localhost:8080', APP_BASE_URL: 'http://localhost:8080/application' }) diff --git a/api/services/github/auth.js b/api/services/github/auth.js index 175e5f7..fcb3ec4 100644 --- a/api/services/github/auth.js +++ b/api/services/github/auth.js @@ -3,12 +3,13 @@ const path = require('path') const jwt = require('jsonwebtoken') const api = require('./api') +const config = require('../../config') const pemPath = path.join(__dirname, '..', '..', '..', 'private-key.pem') -const privateKey = process.env.GITHUB_APP_PRIVATE_KEY || fs.readFileSync(pemPath) +const privateKey = config.GITHUB_APP_PRIVATE_KEY || fs.readFileSync(pemPath) function createAppToken () { - return jwt.sign({ iss: process.env.GITHUB_APP_ID }, privateKey, { + return jwt.sign({ iss: config.GITHUB_APP_ID }, privateKey, { algorithm: 'RS256', expiresIn: '10m' }) @@ -24,8 +25,8 @@ function createOauthFlowUrl () { const redirectUrl = new URL('https://github.com/login/oauth/authorize') redirectUrl.search = new URLSearchParams({ - client_id: process.env.GITHUB_CLIENT_ID, - redirect_uri: process.env.GITHUB_OAUTH_CALLBACK_URL, + client_id: config.GITHUB_CLIENT_ID, + redirect_uri: config.GITHUB_OAUTH_CALLBACK_URL, state: 'foo' }).toString() @@ -33,7 +34,7 @@ function createOauthFlowUrl () { } function createOauthReturnUrl (token) { - const url = new URL(process.env.APP_BASE_URL) + const url = new URL(config.APP_BASE_URL) url.search = new URLSearchParams({ token }).toString() return url.toString() } @@ -46,8 +47,8 @@ function getOauthToken (code) { Accept: 'application/json' }, data: { - client_id: process.env.GITHUB_CLIENT_ID, - client_secret: process.env.GITHUB_CLIENT_SECRET, + client_id: config.GITHUB_CLIENT_ID, + client_secret: config.GITHUB_CLIENT_SECRET, code } }) diff --git a/application/components/keyboard-picker.vue b/application/components/keyboard-picker.vue index c3b6383..dec3e37 100644 --- a/application/components/keyboard-picker.vue +++ b/application/components/keyboard-picker.vue @@ -41,7 +41,7 @@ export default { sourceChoices, source: onlySource || ( sourceChoices.find(source => source.id === selectedSource) - ? selectedSource.id + ? selectedSource : null ) } @@ -1,6 +1,5 @@ -const process = require('process') const api = require('./api') +const config = require('./api/config') -const PORT = process.env.PORT || 8080 -api.listen(PORT) -console.log('listening on', PORT) +api.listen(config.PORT) +console.log('listening on', config.PORT) |