Skip to content
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ typings/

# dotenv environment variables file
.env
.env.*
!.env-template

# Adding the swagger project files:
api_project.sublime-project
Expand Down
4 changes: 1 addition & 3 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.12.0.cjs
nodeLinker: node-modules
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN yarn install
RUN corepack enable
COPY package.json yarn.lock .yarnrc.yml ./
RUN yarn install --immutable
COPY . .
EXPOSE 3001
CMD ["npm", "start"]
CMD ["npm", "start"]
68 changes: 43 additions & 25 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ const dbtest = require('./database/pgp_db').dbheader;
const rateLimiter = require('express-rate-limit');
const dotenv = require('dotenv');

dotenv.config();
const env = process.env.NODE_ENV || 'development';
dotenv.config({ path: `.env.${env}` });
console.log(`Loaded environment from .env.${env}`);

Comment on lines +18 to +21
const apiPort = parseInt(process.env.APIPORT, 10) || 3001;

const app = express();
const cache = apicache.middleware;
Expand All @@ -33,18 +37,47 @@ const limiter = rateLimiter({

app.engine('html', require('ejs').renderFile);

// app.use(helmet());
app.use(cors());
const {optionalAuth} = require('./v2.0/helpers/validation/sessionauth');
const corsOptions = {
origin: function(origin, callback) {
// Allow requests with no Origin header (server-to-server, R package, curl, etc.)
if (!origin) return callback(null, true);

const allowed = [
'http://localhost:5173',
'http://127.0.0.1:5173',
'https://data.neotomadb.org',
// add other frontends as needed
];

if (allowed.includes(origin)) {
return callback(null, true);
}
// 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 +56 to +63

app.use(cors(corsOptions));
app.use(limiter);
app.use(express.json());
// app.use(cache('5 minutes'));
app.use(express.static('mochawesome-report'));
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(compression());
app.use(express.static('public'));
app.use(express.static('mochawesome-report'));
app.use(express.static(path.join(__dirname, 'public')));
// Attach req.user (or null) on every request.
// Routes that need to *require* auth use requireAuth instead.
app.use(optionalAuth);

app.locals.db = dbtest();

// test trigger watch restart - 09/12/20
//
// create a write stream (in append mode)

const pad = (num) => (num > 9 ? '' : '0') + num;
Expand Down Expand Up @@ -72,7 +105,7 @@ app.use(morgan(':date[iso]\t:remote-addr\t:method\t:url\t:status\t:res[content-l
}));

const options = {
swaggerUrl: 'http://localhost:3005/api-docs',
swaggerUrl: `http://localhost:${apiPort}/api-docs`,
customCssUrl: '/custom.css',
};

Expand All @@ -99,17 +132,6 @@ const healthwatch = require('./v2.0/routes/healthwatch');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));

app.use(express.static('public'));
app.use(express.urlencoded({
extended: false,
}));
app.use(express.json());
app.use(cookieParser());

app.use(express.static(path.join(__dirname, 'public')));

// optionally, re-factor route paths here to strip version string and
// identify version from header; still requires version directory paths in
Expand Down Expand Up @@ -173,12 +195,8 @@ app.all('*', function(req, res) {
// in production, port is 3001 and server started in script 'www'
// The variable is stored in the gitignored `.env` file.
// This is managed in the www folder.
if (process.env.NODE_ENV === 'development') {
app.listen(3005);
}

if (process.env.NODE_ENV === 'production') {
app.listen(3001);
}
app.listen(apiPort, () => {
console.log(`Neotoma API listening on port ${apiPort} (NODE_ENV=${process.env.NODE_ENV})`);
});

module.exports = app;
22 changes: 13 additions & 9 deletions genoatt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ This bash script also performs some text replacement to account for issues in th
* We ensure that all altmin values are lower than altmax values.

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 14 to +20

HELP
}
Expand All @@ -29,8 +30,8 @@ run_oatt() {

# oatts is a bit silly in picking its variables. We need to make sure that we're
# getting the proper polygons, and making sure altmin/altmax are appropriate.
find ./test/*.js -type f -exec sed -i.old -E 's/"loc":\ "\{.*?\}"/"loc": "{\"type\":\"Polygon\",\"coordinates\":[[[-104.053249,41.001406],[-104.675999,41.000957],[-104.855273,40.998048],[-105.277138,40.998173],[-105.730421,40.996886],[-106.217573,40.997734],[-106.453859,41.002057],[-106.857773,41.002663],[-107.625624,41.002124],[-108.250649,41.000114],[-108.884138,41.000094],[-109.050076,41.000659],[-109.048044,40.619231],[-109.050946,40.444368],[-109.050615,39.87497],[-109.051363,39.497674],[-109.051512,39.126095],[-109.054189,38.874984],[-109.059541,38.719888],[-109.060062,38.275489],[-109.041762,38.16469],[-109.041058,37.907236],[-109.041865,37.530726],[-109.04581,37.374993],[-109.045223,36.999084],[-108.620309,36.999287],[-108.249358,36.999015],[-108.000623,37.000001],[-107.420913,37.000005],[-106.877292,37.000139],[-106.869796,36.992426],[-106.201469,36.994122],[-105.62747,36.995679],[-105.1208,36.995428],[-105.000554,36.993264],[-104.338833,36.993535],[-103.733247,36.998016],[-103.002199,37.000104],[-102.814616,37.000783],[-102.698142,36.995149],[-102.04224,36.993083],[-102.041974,37.352613],[-102.041574,37.680436],[-102.044644,38.045532],[-102.045324,38.453647],[-102.045388,38.813392],[-102.048449,39.303138],[-102.050422,39.646048],[-102.051744,40.003078],[-102.051725,40.537839],[-102.051614,41.002377],[-102.556789,41.002219],[-102.865784,41.001988],[-103.497447,41.001635],[-104.053249,41.001406]]]}"/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"loc":\ \"\{.*?\}\"/"loc": "{\"type\":\"Polygon\",\"coordinates\":[[[-104.053249,41.001406],[-104.675999,41.000957],[-104.855273,40.998048],[-105.277138,40.998173],[-105.730421,40.996886],[-106.217573,40.997734],[-106.453859,41.002057],[-106.857773,41.002663],[-107.625624,41.002124],[-108.250649,41.000114],[-108.884138,41.000094],[-109.050076,41.000659],[-109.048044,40.619231],[-109.050946,40.444368],[-109.050615,39.87497],[-109.051363,39.497674],[-109.051512,39.126095],[-109.054189,38.874984],[-109.059541,38.719888],[-109.060062,38.275489],[-109.041762,38.16469],[-109.041058,37.907236],[-109.041865,37.530726],[-109.04581,37.374993],[-109.045223,36.999084],[-108.620309,36.999287],[-108.249358,36.999015],[-108.000623,37.000001],[-107.420913,37.000005],[-106.877292,37.000139],[-106.869796,36.992426],[-106.201469,36.994122],[-105.62747,36.995679],[-105.1208,36.995428],[-105.000554,36.993264],[-104.338833,36.993535],[-103.733247,36.998016],[-103.002199,37.000104],[-102.814616,37.000783],[-102.698142,36.995149],[-102.04224,36.993083],[-102.041974,37.352613],[-102.041574,37.680436],[-102.044644,38.045532],[-102.045324,38.453647],[-102.045388,38.813392],[-102.048449,39.303138],[-102.050422,39.646048],[-102.051744,40.003078],[-102.051725,40.537839],[-102.051614,41.002377],[-102.556789,41.002219],[-102.865784,41.001988],[-103.497447,41.001635],[-104.053249,41.001406]]]}"/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"loc":\ "\{[^}]*\}"/"loc": "{\"type\":\"Polygon\",\"coordinates\":[[[-104.053249,41.001406],[-104.675999,41.000957],[-104.855273,40.998048],[-105.277138,40.998173],[-105.730421,40.996886],[-106.217573,40.997734],[-106.453859,41.002057],[-106.857773,41.002663],[-107.625624,41.002124],[-108.250649,41.000114],[-108.884138,41.000094],[-109.050076,41.000659],[-109.048044,40.619231],[-109.050946,40.444368],[-109.050615,39.87497],[-109.051363,39.497674],[-109.051512,39.126095],[-109.054189,38.874984],[-109.059541,38.719888],[-109.060062,38.275489],[-109.041762,38.16469],[-109.041058,37.907236],[-109.041865,37.530726],[-109.04581,37.374993],[-109.045223,36.999084],[-108.620309,36.999287],[-108.249358,36.999015],[-108.000623,37.000001],[-107.420913,37.000005],[-106.877292,37.000139],[-106.869796,36.992426],[-106.201469,36.994122],[-105.62747,36.995679],[-105.1208,36.995428],[-105.000554,36.993264],[-104.338833,36.993535],[-103.733247,36.998016],[-103.002199,37.000104],[-102.814616,37.000783],[-102.698142,36.995149],[-102.04224,36.993083],[-102.041974,37.352613],[-102.041574,37.680436],[-102.044644,38.045532],[-102.045324,38.453647],[-102.045388,38.813392],[-102.048449,39.303138],[-102.050422,39.646048],[-102.051744,40.003078],[-102.051725,40.537839],[-102.051614,41.002377],[-102.556789,41.002219],[-102.865784,41.001988],[-103.497447,41.001635],[-104.053249,41.001406]]]}"/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"loc":\ \"\{[^}]*\}\"/"loc": "{\"type\":\"Polygon\",\"coordinates\":[[[-104.053249,41.001406],[-104.675999,41.000957],[-104.855273,40.998048],[-105.277138,40.998173],[-105.730421,40.996886],[-106.217573,40.997734],[-106.453859,41.002057],[-106.857773,41.002663],[-107.625624,41.002124],[-108.250649,41.000114],[-108.884138,41.000094],[-109.050076,41.000659],[-109.048044,40.619231],[-109.050946,40.444368],[-109.050615,39.87497],[-109.051363,39.497674],[-109.051512,39.126095],[-109.054189,38.874984],[-109.059541,38.719888],[-109.060062,38.275489],[-109.041762,38.16469],[-109.041058,37.907236],[-109.041865,37.530726],[-109.04581,37.374993],[-109.045223,36.999084],[-108.620309,36.999287],[-108.249358,36.999015],[-108.000623,37.000001],[-107.420913,37.000005],[-106.877292,37.000139],[-106.869796,36.992426],[-106.201469,36.994122],[-105.62747,36.995679],[-105.1208,36.995428],[-105.000554,36.993264],[-104.338833,36.993535],[-103.733247,36.998016],[-103.002199,37.000104],[-102.814616,37.000783],[-102.698142,36.995149],[-102.04224,36.993083],[-102.041974,37.352613],[-102.041574,37.680436],[-102.044644,38.045532],[-102.045324,38.453647],[-102.045388,38.813392],[-102.048449,39.303138],[-102.050422,39.646048],[-102.051744,40.003078],[-102.051725,40.537839],[-102.051614,41.002377],[-102.556789,41.002219],[-102.865784,41.001988],[-103.497447,41.001635],[-104.053249,41.001406]]]}"/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"altmin":(\ )*-*[0-9]+/"altmin":\ 10/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"altmax":(\ )*-*[0-9]+/"altmax":\ 100/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"ageold":(\ )*-*[0-9]+/"ageold":\ 10000/g' {} \;
Expand All @@ -41,8 +42,8 @@ run_oatt() {
find ./test/*.js -type f -exec sed -i.old -E 's/"limit":(\ )*-*[0-9]+/"limit":\ 10/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"offset":(\ )*-*[0-9]+/"offset":\ 0/g' {} \;
find ./test/*.js -type f -exec sed -i.old 's/\/[0-9]\{5,\}/\/500/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"prec":(\ )*[0-9\.]*?/"prec": 1000/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"proj":(\ )*[0-9\.]*?/"proj": 4326/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"prec":(\ )*[0-9.]*/"prec": 1000/g' {} \;
find ./test/*.js -type f -exec sed -i.old -E 's/"proj":(\ )*[0-9.]*/"proj": 4326/g' {} \;
rm -f ./test/*.old
}

Expand All @@ -53,7 +54,7 @@ run_oatt() {
test=0
remote=localhost:3001

while getopts "htdpa" opt; do
while getopts "htldpa" opt; do
case $opt in
h)
show_help
Expand All @@ -62,7 +63,10 @@ remote=localhost:3001
t)
test=1
;;
d)
l)
remote=localhost:3005
;;
d)
remote=api-dev.neotomadb.org
;;
p)
Expand Down
6 changes: 5 additions & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"ext": "sql js json yaml",
"ignore": [
".git",
"node_modules/**/node_modules"
"node_modules/**/node_modules",
"test/**",
"public/**",
"openapi.yaml",
"*.old"
]
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"private": true,
"scripts": {
"start": "NODE_ENV=production nodemon --legacy-watch app.js",
"dev": "NODE_ENV=development nodemon --legacy-watch app.js",
"test": "node ./node_modules/mocha/bin/mocha --config=test/.mocharc.yml --reporter-options reportDir=public,reportFilename=tests",
"build:openapi": "(cd ./openapi && node ./scripts/build-openapi.js)",
"validate:openapi": "yarn build:openapi && bash genoatt.sh && sleep 4 && bash runmochabatch.sh"
Expand Down Expand Up @@ -72,5 +73,6 @@
"nodemon": "^3.1.4",
"pre-commit": "^1.0.10",
"supertest": "^7.2.2"
}
},
"packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8"
}
2 changes: 1 addition & 1 deletion public/tests.html

Large diffs are not rendered by default.

Loading
Loading