Skip to content

Commit d18c254

Browse files
committed
Add support for CDN asset hosting
Supports setting an env var for CDN_ASSET_HOST. Doing so will prepend the asset urls that are built in asset_resolver with a cdn. For this to work, you need to set CDN_ASSET_HOST=https://cdn.com Then upload everything from packages/app/obojobo-express/server/public to the cdn after running yarn build.
1 parent 3c5e7b8 commit d18c254

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,36 @@ Once logged in, visit [https://127.0.0.1:8080/editor](https://127.0.0.1:8080/edi
6666

6767
`yarn test` or `yarn test:ci`
6868

69+
### Deployment and Setup
70+
71+
For deployment, there are several places you can set configuration options. Obojobo uses a hybrid of json files and environment variables. We are moving more toward using more environment variables. However, json config files can be found in several obojobo packages (they are usually in server/config/*.json files). Below are a set of environment variables that we recommend using
72+
73+
- `CDN_ASSET_HOST`: If you want to host compiled browser assets (js/css/etc) on a CDN. Ex value: `https://site.com`
74+
- `NODE_ENV`: determines which environment from the config files will be used. Use production unless you have a use for multiple environments.
75+
- `DB_USER`: db user
76+
- `DB_PASS`: db pass
77+
- `DB_HOST`: db host
78+
- `DB_NAME`: db name
79+
- `DB_PORT`: db port
80+
- `DB_SSL_JSON`: enable or disable using ssl to connect to the database
81+
- `DB_TIMEOUT`: ex: 29000. Used to set the pg-promise settings for query_timeout and statement_timeout.
82+
- `OBO_LTI_KEYS_JSON`: ex: '{"key1":"secret1","key2":"secret2}'. Use json string to define valid lti key/secret pairs.
83+
- `OBO_LTI_USERNAME_PARAM`: What lti launch param do you want to use as the username in obojobo. ex: `user_id` or `lis_person_sourcedid`
84+
- `OBO_COOKIE_SECRET`: Randomized secret key that is used to encrypt cookies. See the docs for express-session.
85+
- `OBO_COOKIE_SECURE`: Set to true when using https. See docs for express-session. Used to set secure, sameSite and httpOnly options.
86+
- `DEBUG`: Logging Verbosity. Use obojobo_server:* for more output. ex: `obojobo_server:error,obojobo_server:warn`
87+
- `YARN_PRODUCTION`: Set to true. Makes sure yarn install includes dev dependencies.
88+
- `OBO_DEMO_PURGE_MODE`: Automatically purge old data for demo purposes or to limit database growth. Additional addon setup required. ex: disabled (default), DANGER-delete-HISTORY-data, DANGER-delete-ALL-data
89+
- `OBO_DEMO_PURGE_DAYS_AGO`: If purge mode is enabled, purge data older than this many days. ex: 7
90+
- `OBO_EDITLOCK_TIME_UNTIL_RELEASE_MINUTES`: Editor lock: period of inactivity to release the lock. ex: 45
91+
- `OBO_EDITLOCK_TIME_UNTIL_WARN_MINUTES`: Editor lock: period of inactivity to warn the user about lock release. ex: 40
92+
- `OBO_EDITLOCK_DB_LOCK_DURATION`: Editor lock: period of time a lock lasts unless it is renewed. ex: 5
93+
- `OBO_LTI_GUID`: A GUID unique to this install of Obojobo. Google LTI launch param tool_consumer_instance_guid for more details. ex: `edu.your-school.obojobo`
94+
- `MATERIA_OAUTH_KEY`: LTI Oauth key used just for the optional Materia integration.
95+
- `MATERIA_OAUTH_SECRET`: LTI Oauth secret used the optional Materia integration.
96+
- `MATERIA_HOST`: URL for the optional Materia integration. ex: https://your.materia.com
97+
- `OBO_OPTIONAL_NODES`: Comma separated list of optional nodes that are already installed to enable. ex: `*` or `obojobo-chunks-materia`
98+
6999
### Special Thanks
70100

71101
Support for this work was provided by the National Science Foundation Scholarships in Science, Technology, Engineering, and Mathematics (S-STEM) program under [Award No.1643835](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1643835). Any opinions, findings, conclusions and recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

packages/app/obojobo-express/__tests__/asset_resolver.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ const { assetForEnv } = require('../server/asset_resolver')
1414
describe('Asset Resolver', () => {
1515
const originalNODE_ENV = process.env.NODE_ENV
1616
const originalIS_WEBPACK = process.env.IS_WEBPACK
17+
const originalCDN_ASSET_HOST = process.env.CDN_ASSET_HOST
1718

1819
afterAll(() => {
1920
process.env.NODE_ENV = originalNODE_ENV
2021
process.env.IS_WEBPACK = originalIS_WEBPACK
22+
process.env.CDN_ASSET_HOST = originalCDN_ASSET_HOST
2123
})
2224

2325
beforeEach(() => {
2426
jest.resetModules()
2527
delete process.env.NODE_ENV
2628
delete process.env.ASSET_ENV
2729
delete process.env.IS_WEBPACK
30+
delete process.env.CDN_ASSET_HOST
2831
})
2932

3033
test('assetForEnv builds pattern for dev server', () => {
@@ -90,4 +93,14 @@ describe('Asset Resolver', () => {
9093
expect(webpackAssetPath('subdir/test.json')).toBe('/static-from-manifest/subdir/test.json')
9194
expect(webpackAssetPath('asset-that-doesnt-exist.js')).toBe(undefined) //eslint-disable-line no-undefined
9295
})
96+
97+
test('CDN_ASSET_HOST is prepended to manifest assets when present', () => {
98+
process.env.IS_WEBPACK = 'false'
99+
process.env.CDN_ASSET_HOST = 'https://test-cdn-value.com'
100+
const { webpackAssetPath } = require('../server/asset_resolver')
101+
102+
expect(webpackAssetPath('test.js')).toBe(
103+
'https://test-cdn-value.com/static-from-manifest/test.js'
104+
)
105+
})
93106
})

packages/app/obojobo-express/server/asset_resolver.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ const getEnv = forceEnvTo => {
4343
return (env || NODE_ENV).toLowerCase()
4444
}
4545

46+
const resolveFromManifest = assetName => {
47+
// eslint-disable-next-line no-undefined
48+
if (!manifest[assetName]) return undefined
49+
return `${process.env.CDN_ASSET_HOST || ''}${manifest[assetName]}`
50+
}
51+
52+
// use the original name in the static path
53+
const resolveFromWebpackDevServer = assetName => `/static/${assetName}`
54+
4655
const IS_WEBPACK = process.env.IS_WEBPACK === 'true'
4756
// NOTE: manifest created via `yarn build`
4857
const manifest = IS_WEBPACK ? {} : require('./public/compiled/manifest.json')
49-
const webpackAssetPath = IS_WEBPACK
50-
? assetName => `/static/${assetName}` // use the original name in the static path
51-
: assetName => manifest[assetName] // return path from the manifest
58+
const webpackAssetPath = IS_WEBPACK ? resolveFromWebpackDevServer : resolveFromManifest
5259

5360
module.exports = {
5461
assetForEnv,

0 commit comments

Comments
 (0)