Skip to content

Develop#215

Merged
sedv8808 merged 13 commits into
productionfrom
develop
May 12, 2026
Merged

Develop#215
sedv8808 merged 13 commits into
productionfrom
develop

Conversation

@sedv8808
Copy link
Copy Markdown
Collaborator

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:

  • Added new session authentication middleware (optionalAuth and requireAuth) in v2.0/helpers/validation/sessionauth.js to 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))
  • Integrated optionalAuth into the main Express middleware stack in app.js, ensuring req.user is available on all requests. ([app.jsL36-L47](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-e07d531ac040ce3f40e0ce632ac2a059d7cd60f20e61f78268ac3be015b3b28fL36-L47))

Environment and Configuration Improvements:

  • Refactored environment variable loading in app.js to use .env.development, .env.production, etc., based on NODE_ENV, and standardized port selection via APIPORT. ([[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))
  • Updated the Dockerfile and Yarn configuration for Yarn 4, using corepack and the --immutable install flag, and removed the yarnPath override. ([[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:

  • Implemented a custom CORS policy in app.js to 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:

  • Improved test scripts: added new flags for local/remote environments in genoatt.sh and runmochabatch.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))
  • Relaxed Mocha test runner settings for better CI stability: increased timeout, disabled bail and retries, and reduced parallel jobs. ([test/.mocharc.ymlL2-R13](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-87ae3a54ae4e259ede402e65f7f194c264918307dd1c39536a58407f5743c868L2-R13))
  • Skipped a broken test in test/datasets.js with a TODO for future fixes. ([test/datasets.jsL90-R97](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-f7ed8661159d9864a64fff963e00b9f5cdbfe1d0111c6272d76cfc7368d88c31L90-R97))
  • Updated nodemon.json to 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:

  • Added a dev script to package.json for running the server in development mode. ([package.jsonR15](https://github.com/NeotomaDB/api_nodetest/pull/215/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R15))
  • Fixed and improved regexes in test scripts for more robust test data patching. ([[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.

Copilot AI review requested due to automatic review settings May 11, 2026 23:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/whoami and /v2.0/apps/logout routes.
  • Refactored environment loading to .env.<NODE_ENV> and standardized server port selection via APIPORT.
  • 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 thread app.js
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 thread app.js
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}`);

Comment thread app.js
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 thread v2.0/routes/apps.js
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 thread v2.0/routes/apps.js
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'});
}
Comment thread runmochabatch.sh

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 thread genoatt.sh
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 thread test/datasets.js
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) {
@sedv8808 sedv8808 merged commit c201374 into production May 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants