Skip to content

Commit

Permalink
Move non-entrypoint JavaScript into src/
Browse files Browse the repository at this point in the history
While there may have been some rhyme or reason for creating these files
outside of src/ originally, it's no longer apparent.  It's nice to
systematize the file organization a bit, esp. in advance of additional
files I'm planning to add to support new server-side API endpoints.
  • Loading branch information
tsibley committed Oct 27, 2021
1 parent aed0232 commit 49ba156
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Nextstrain documentation is hosted by Read The Docs at [docs.nextstrain.org](htt
Please see [this GitHub repo](https://github.com/nextstrain/docs.nextstrain.org/) for more details.

> Note that the documentation used to be served from the server in this repo at URLs such as nextstrain.org/docs/... until [November 2020](https://github.com/nextstrain/nextstrain.org/pull/226).
A number of [redirects](./redirects.js) have been added to preserve old URLs.
A number of [redirects](./src/redirects.js) have been added to preserve old URLs.

---
## Auspice client
Expand Down
4 changes: 2 additions & 2 deletions docs/infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Deploys of `master` happen automatically after Travis CI tests are successful.

- `REDIS_URL` is provided by the Heroku Redis add-on.
It should not be modified directly.
Our [authentication handlers](../authn.js) rewrite it at server start to use a secure TLS connection.
Our [authentication handlers](../src/authn/index.js) rewrite it at server start to use a secure TLS connection.

- `FETCH_CACHE` is not currently used, but can be set to change the location of the on-disk cache used by (some) server `fetch()`-es.
The default location is `/tmp/fetch-cache`.
Expand Down Expand Up @@ -107,7 +107,7 @@ Ephemeral instances are automatically managed by AWS Batch for `nextstrain build
## Cognito

A [_user pool_](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools.html) called `nextstrain.org` provides authentication for Nextstrain logins.
Cognito is integrated with the nextstrain.org server using the OAuth2 support from PassportJS in our [`authn.js`](../authn.js) file.
Cognito is integrated with the nextstrain.org server using the OAuth2 support from PassportJS in our [`authn/index.js`](../src/authn/index.js) file.

We currently don't use Cognito's [_identity pools_](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-identity.html).
It may be beneficial to use one in the future so we can get temporary AWS credentials specific to each Nextstrain user with the appropriate authorizations baked in (instead of using a server-wide set of credentials).
Expand Down
6 changes: 3 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const favicon = require('serve-favicon');
const compression = require('compression');
const argparse = require('argparse');
const utils = require("./src/utils");
const { potentialAuspiceRoutes, isRequestBackedByAuspiceDataset } = require('./auspicePaths');
const { potentialAuspiceRoutes, isRequestBackedByAuspiceDataset } = require('./src/auspicePaths');
const cors = require('cors');
const {addAsync} = require("@awaitjs/express");
const {NotFound} = require('http-errors');
Expand Down Expand Up @@ -37,8 +37,8 @@ global.verbose = args.verbose;
// Import these after parsing CLI arguments and setting global.verbose so code
// in them can use utils.verbose() at load time.
const auspiceServerHandlers = require("./src/index.js");
const authn = require("./authn");
const redirects = require("./redirects");
const authn = require("./src/authn");
const redirects = require("./src/redirects");

/* Path helpers for static assets, to make routes more readable.
*/
Expand Down
6 changes: 3 additions & 3 deletions auspicePaths.js → src/auspicePaths.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fetch = require("node-fetch");
const sources = require("./src/sources");
const { warn } = require("./src/utils");
const { splitPrefixIntoParts, parsePrefix } = require("./src/getDatasetHelpers");
const sources = require("./sources");
const { warn } = require("./utils");
const { splitPrefixIntoParts, parsePrefix } = require("./getDatasetHelpers");

/**
* Auspice core builds have URLs where the first (`/`-separated) field matches the following list.
Expand Down
6 changes: 3 additions & 3 deletions authn.js → src/authn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const OAuth2Strategy = require("passport-oauth2").Strategy;
const {jwtVerify} = require('jose/jwt/verify'); // eslint-disable-line import/no-unresolved
const {createRemoteJWKSet} = require('jose/jwks/remote'); // eslint-disable-line import/no-unresolved
const {JOSEError, JWTClaimValidationFailed} = require('jose/util/errors'); // eslint-disable-line import/no-unresolved
const BearerStrategy = require("./src/authn/bearer");
const sources = require("./src/sources");
const utils = require("./src/utils");
const BearerStrategy = require("./bearer");
const sources = require("../sources");
const utils = require("../utils");

const PRODUCTION = process.env.NODE_ENV === "production";

Expand Down
4 changes: 2 additions & 2 deletions redirects.js → src/redirects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const url = require('url');
const helpers = require("./src/getDatasetHelpers");
const { parseNarrativeLanguage } = require("./src/utils");
const helpers = require("./getDatasetHelpers");
const { parseNarrativeLanguage } = require("./utils");

const setup = (app) => {

Expand Down
2 changes: 1 addition & 1 deletion static-site/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { createProxyMiddleware } = require("http-proxy-middleware");
const config = require("./data/SiteConfig");
const {potentialAuspiceRoutes} = require("../auspicePaths");
const {potentialAuspiceRoutes} = require("../src/auspicePaths");

// const pathPrefix = config.pathPrefix === "/" ? "" : config.pathPrefix;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/routing.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {isRequestBackedByAuspiceDataset} = require("../../auspicePaths.js");
const {isRequestBackedByAuspiceDataset} = require("../../src/auspicePaths.js");

jest.setTimeout(10000);

Expand Down

0 comments on commit 49ba156

Please sign in to comment.