Develop#215
Merged
Merged
Conversation
…d passing it into Neotoma or logging it out
OI-29 updating yarn in dockerfile
OI-29 updating yarn in dockerfile
There was a problem hiding this comment.
Pull request overview
This PR updates the Neotoma Node/Express API’s development workflow by introducing session-based authentication middleware, tightening/reshaping environment + Docker/Yarn setup, and adjusting test tooling/configuration for improved local/CI ergonomics.
Changes:
- Added session token auth middleware (
optionalAuth/requireAuth) and wired it into the Express middleware stack, plus new authenticated/v2.0/apps/whoamiand/v2.0/apps/logoutroutes. - Refactored environment loading to
.env.<NODE_ENV>and standardized server port selection viaAPIPORT. - Updated Docker/Yarn/test scripts and Mocha settings to better support Yarn 4 and improve test stability.
Reviewed changes
Copilot reviewed 11 out of 15 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
app.js |
Loads env from .env.<env>, sets port from APIPORT, adds global optional auth and new CORS/static middleware ordering. |
v2.0/helpers/validation/sessionauth.js |
New bearer-session authentication middleware used across routes. |
v2.0/routes/apps.js |
Adds authenticated /whoami and /logout endpoints using requireAuth. |
Dockerfile |
Switches to corepack + Yarn 4 install (--immutable) and copies Yarn config files. |
package.json |
Adds dev script and pins Yarn via packageManager. |
.yarnrc.yml |
Removes yarnPath override; keeps node-modules linker. |
yarn.lock |
Dependency lock updates consistent with Yarn 4 resolution changes. |
test/.mocharc.yml |
Relaxes Mocha runner settings (timeouts/retries/jobs/bail) for CI stability. |
test/datasets.js |
Skips a broken test with TODO notes for later repair. |
genoatt.sh |
Adds local-dev flag and improves sed regex robustness for generated tests. |
runmochabatch.sh |
Adjusts defaults/flags for selecting test targets; adds guidance comment. |
nodemon.json |
Ignores tests/public/generated outputs to speed up reloads during development. |
.gitignore |
Ignores .env.* files while keeping .env-template tracked. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+56
to
+63
| // For now, log and allow — Neotoma data is public. | ||
| // Tighten this later if you ever return user-specific data based on Origin. | ||
| console.warn('CORS: unrecognized origin allowed:', origin); | ||
| return callback(null, true); | ||
| }, | ||
| credentials: true, | ||
| allowedHeaders: ['Content-Type', 'Authorization'], | ||
| }; |
Comment on lines
+18
to
+21
| const env = process.env.NODE_ENV || 'development'; | ||
| dotenv.config({ path: `.env.${env}` }); | ||
| console.log(`Loaded environment from .env.${env}`); | ||
|
|
| app.use(express.urlencoded({ extended: false })); | ||
| app.use(cookieParser()); | ||
| app.use(compression()); | ||
| app.use(express.static('public')); |
Comment on lines
+20
to
+21
| const parts = header.split(' '); | ||
| if (parts.length !== 2 || parts[0] !== 'Bearer') return null; |
| if (!token) { | ||
| return res.status(401).json({ | ||
| status: 'unauthorized', | ||
| message: 'Missing Authorization header', |
Comment on lines
+19
to
+23
| router.get('/whoami', requireAuth, function(req, res) { | ||
| res.status(200).json({ | ||
| status: 'success', | ||
| data: { | ||
| orcidid: req.user.orcidid, |
Comment on lines
+41
to
+44
| res.status(200).json({status: 'success', message: 'Session ended'}); | ||
| } catch (err) { | ||
| res.status(500).json({status: 'error', message: 'Logout failed'}); | ||
| } |
|
|
||
| run_mocha() { | ||
| # Only run v2.0 tests locally 'v2.0-*.js' — v1.5 endpoints are slow and trip chakram's default timeout | ||
| find ./test -name '*.js' | shuf | xargs mocha --config=test/.mocharc.yml --reporter-options reportDir=public,reportFilename=tests |
Comment on lines
14
to
+20
| Options: | ||
| [none] build the mocha tests and exit | ||
| [none] build the mocha tests and exit (targets localhost:3001 — local production mode) | ||
| -h display this help and exit | ||
| -t build the tests and run "npm test" | ||
| -d build the tests for the remove development server at api-dev. | ||
| -p build the tests for the remove production server at api.neotomadb.org | ||
| -l build the tests for the LOCAL DEV server at localhost:3005 (NODE_ENV=development) | ||
| -d build the tests for the remote development server at api-dev. | ||
| -p build the tests for the remote production server at api.neotomadb.org |
Comment on lines
+90
to
+97
| // TODO: re-enable once the assertion is rewritten. Currently broken in two ways: | ||
| // 1. Bitwise & instead of logical && — `test` becomes 0/1, never === false, so the | ||
| // loop always returns true and never catches a real failure. | ||
| // 2. Nested property access (data[i].site.datasets[0].agerange.ageyoung) throws when | ||
| // any link is null/undefined; supertest swallows the exception and done() never | ||
| // fires, causing the per-test 50s timeout. Fix with optional chaining + throw on | ||
| // assertion failure inside the .expect(fn) callback. | ||
| it.skip('Works with age validation:', function(done) { |
OI-29 updating yarn in dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements to the development workflow, environment configuration, authentication middleware, and test infrastructure. The most significant changes include adding session-based authentication middleware, refactoring environment variable handling, updating Docker and Yarn setup, and improving test scripts and configuration.
Authentication and Middleware Enhancements:
optionalAuthandrequireAuth) inv2.0/helpers/validation/sessionauth.jsto support bearer token authentication and attach user info to requests. ([v2.0/helpers/validation/sessionauth.jsR1-R100](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-88833003bfec6b48cefbc1c25381da569e46d322a94ac0e263a3382e964f3273R1-R100))optionalAuthinto the main Express middleware stack inapp.js, ensuringreq.useris available on all requests. ([app.jsL36-L47](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-e07d531ac040ce3f40e0ce632ac2a059d7cd60f20e61f78268ac3be015b3b28fL36-L47))Environment and Configuration Improvements:
app.jsto use.env.development,.env.production, etc., based onNODE_ENV, and standardized port selection viaAPIPORT. ([[1]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-e07d531ac040ce3f40e0ce632ac2a059d7cd60f20e61f78268ac3be015b3b28fL18-R22),[[2]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-e07d531ac040ce3f40e0ce632ac2a059d7cd60f20e61f78268ac3be015b3b28fL176-R200))corepackand the--immutableinstall flag, and removed theyarnPathoverride. ([[1]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L3-R5),[[2]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-88fbe28c4102501b94961511a0d70ff895bf39970b4d3fc11917794a239117c5L2-L3),[[3]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L75-R77))CORS and Static File Handling:
app.jsto allow only specific origins, with logging for unrecognized origins. Improved static file serving and middleware order for better compatibility. ([[1]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-e07d531ac040ce3f40e0ce632ac2a059d7cd60f20e61f78268ac3be015b3b28fL36-L47),[[2]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-e07d531ac040ce3f40e0ce632ac2a059d7cd60f20e61f78268ac3be015b3b28fL102-L112))Testing and Scripts:
genoatt.shandrunmochabatch.sh, updated defaults, and clarified help messages. ([[1]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-f1e24b6aa45aaca7f463be2d7313316079de44ffd844aed34c1b821a70c787fdL15-R20),[[2]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-f1e24b6aa45aaca7f463be2d7313316079de44ffd844aed34c1b821a70c787fdL56-R57),[[3]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-f1e24b6aa45aaca7f463be2d7313316079de44ffd844aed34c1b821a70c787fdR66-R68),[[4]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-b8d8243a4aabb939af34649990b2827d892ec761de1637b6dadd86ba99af4fadR30-R33),[[5]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-b8d8243a4aabb939af34649990b2827d892ec761de1637b6dadd86ba99af4fadL45-R51))[test/.mocharc.ymlL2-R13](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-87ae3a54ae4e259ede402e65f7f194c264918307dd1c39536a58407f5743c868L2-R13))test/datasets.jswith a TODO for future fixes. ([test/datasets.jsL90-R97](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-f7ed8661159d9864a64fff963e00b9f5cdbfe1d0111c6272d76cfc7368d88c31L90-R97))nodemon.jsonto ignore test, public, and generated files for faster reloads during development. ([nodemon.jsonL5-R9](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-1d7174a5b72c6ecace2f5d30dc09a4d6cbba8da4ee95063cba0645c0f27066c6L5-R9))Other Notable Changes:
devscript topackage.jsonfor running the server in development mode. ([package.jsonR15](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R15))[[1]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-f1e24b6aa45aaca7f463be2d7313316079de44ffd844aed34c1b821a70c787fdL32-R34),[[2]](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-f1e24b6aa45aaca7f463be2d7313316079de44ffd844aed34c1b821a70c787fdL44-R46))These changes collectively improve security, environment flexibility, and developer experience.