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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.yarn/cache
.yarn/unplugged
.yarn/install-state.gz
node_modules
.pnp.*
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ ELEVATION_DATABASE=<database_url>
ALICE_DATABASE=<database_url>
ROCKD_DATABASE=<database_url>
WHOS_ON_FIRST_DATABASE=<database_url>

# Settings for debugging
NODE_ENV=development
DEBUG=*
PORT=5002
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ Icon
.Spotlight-V100
.Trashes
.yarn/install-state.gz
.yarn/cache
.yarn/unplugged

.env
.pnp.*

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.yarn
node_modules
.pnp.*
2 changes: 0 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.9.1.cjs
11 changes: 2 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ RUN apt-get -y update && \

WORKDIR /code

COPY ./package.json ./yarn.lock ./code/
COPY package.json yarn.lock .yarnrc.yml /code/
COPY .yarn/releases /code/.yarn/releases

RUN yarn install

# We had to switch to native postgres bindings
# (using the pg-native module) for the purposes
# of building in Docker. I think this is necessary
# to support Postgres v14, but it will make things harder
# to build/run on weird platforms.
# https://github.com/brianc/node-postgres/issues/1508
ENV NODE_PG_FORCE_NATIVE=1

COPY ./ /code/

COPY ./supervisor/api.conf /etc/supervisor/conf.d/
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@macrostrat/api-v2",
"version": "2.1.0-beta.1",
"version": "2.1.0-beta.2",
"description": "An API for stratigraphic and geological information (Version 2).",
"main": "server.js",
"repository": {
Expand Down Expand Up @@ -53,18 +53,18 @@
"geojson-precision": "^0.4.0",
"image-size": "^0.5.0",
"mapshaper": "^0.3.20",
"memory-cache": "^0.1.4",
"memory-cache": "^0.2.0",
"microtime": "^3.0.0",
"multiline": "^1.0.2",
"mysql": "2.7.x",
"pg": "^8.7.1",
"pg-native": "^3.0.0",
"pg": "^8.15.6",
"pg-native": "^3.4.5",
"portscanner": "^1.0.0",
"redis": "^2.4.2",
"tilestrata": "^2.0.1",
"tilestrata-dependency": "^0.4.0",
"topojson": "^1.6.19",
"ts-node": "^10.9.2",
"tsx": "^4.19.3",
"turf-area": "^1.1.1",
"turf-buffer": "^1.0.4",
"turf-point": "^0.1.6",
Expand Down
8 changes: 7 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const dotenv = require("dotenv");
// Load environment variables from .env file
dotenv.config();

console.log(process.env.PORT)

var express = require("express"),
bodyParser = require("body-parser"),
//v1 = require("./v1"),
Expand Down Expand Up @@ -61,7 +67,7 @@ app.use("/", v2);
app.set("json spaces", 2);

//TODO: update port to designated env.
app.port = process.argv[2] || 5000;
app.port = process.argv[2] ?? process.env.PORT ?? 5000;

app.start = function () {
app.listen(app.port, function () {
Expand Down
4 changes: 3 additions & 1 deletion supervisor/api.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[program:api]
command = npm start
directory = /code
user = root
command = yarn start 5000
autorestart = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
Expand Down
4 changes: 0 additions & 4 deletions v2/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const dotenv = require("dotenv");
// Load environment variables from .env file
dotenv.config();

// Set up debug mode if needed
exports.debug = process.env.NODE_ENV === "development";
if (exports.debug) {
Expand Down
8 changes: 5 additions & 3 deletions v2/larkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ const { Client, Pool } = require("pg");
// Check if Redis is available
portscanner.checkPortStatus(6379, "127.0.0.1", function (error, status) {
if (status === "open") {
larkin.trace("Using Redis cache for columns");
larkin.log("Using Redis cache for columns");
var redis = require("redis");
larkin.cache = redis.createClient(6379, "127.0.0.1");
larkin.cache.fetch = function (key, callback) {
Expand All @@ -676,12 +676,13 @@ const { Client, Pool } = require("pg");
});
};
} else {
larkin.trace("Using application cache for columns");
larkin.log("Using memory cache for columns");
larkin.cache = require("memory-cache");
larkin.cache.fetch = function (key, callback) {
callback(larkin.cache.get(key));
};
}
console.log("Initialized cache")
});

/*
Expand All @@ -701,7 +702,7 @@ const { Client, Pool } = require("pg");
//get all units and summarize for columns
http.get(
//TODO: change url to match env.
"http://localhost:5000/v2/units?all&response=long",
"http://0.0.0.0:5000/v2/units?all&response=long",
function (res) {
var body = "";
res.on("data", function (chunk) {
Expand Down Expand Up @@ -888,6 +889,7 @@ const { Client, Pool } = require("pg");
JSON.stringify(results.columnsNoGeom),
);
} else {
larkin.trace("Setting up column cache")
larkin.cache.put("unitSummary", results.unitSummary);
larkin.cache.put("columnsGeom", results.columnsGeom);
larkin.cache.put("columnsNoGeom", results.columnsNoGeom);
Expand Down
Loading