Skip to content

Commit

Permalink
#322 ROOT_PATH, doesn't work fully for /configure yet
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Feb 2, 2023
1 parent e959617 commit 4061387
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 72 deletions.
4 changes: 2 additions & 2 deletions API/Backend/Config/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let setup = {
process.env.HIDE_CONFIG != "true"
) {
s.app.get(
"/configure",
s.ROOT_PATH + "/configure",
s.ensureGroup(s.permissions.users),
s.ensureAdmin(true),
(req, res) => {
Expand All @@ -24,7 +24,7 @@ let setup = {
}

s.app.use(
"/API/configure",
s.ROOT_PATH + "/API/configure",
s.ensureAdmin(),
s.checkHeadersCodeInjection,
s.setContentType,
Expand Down
8 changes: 4 additions & 4 deletions API/Backend/Datasets/setup.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const router = require("./routes/datasets");
let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/datasets",
s.ROOT_PATH + "/API/datasets",
s.ensureAdmin(),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
4 changes: 2 additions & 2 deletions API/Backend/Draw/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use(
"/API/files",
s.ROOT_PATH + "/API/files",
s.ensureUser(),
s.checkHeadersCodeInjection,
s.setContentType,
Expand All @@ -15,7 +15,7 @@ let setup = {
);

s.app.use(
"/API/draw",
s.ROOT_PATH + "/API/draw",
s.ensureUser(),
s.checkHeadersCodeInjection,
s.setContentType,
Expand Down
8 changes: 4 additions & 4 deletions API/Backend/Geodatasets/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ const router = require("./routes/geodatasets");

let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/geodatasets",
s.ROOT_PATH + "/API/geodatasets",
s.ensureAdmin(),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
8 changes: 4 additions & 4 deletions API/Backend/LongTermToken/setup.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const router = require("./routes/longtermtokens");
let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/longtermtoken",
s.ROOT_PATH + "/API/longtermtoken",
s.ensureAdmin(false, true),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
8 changes: 4 additions & 4 deletions API/Backend/Shortener/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ const router = require("./routes/shortener");

let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/shortener",
s.ROOT_PATH + "/API/shortener",
s.ensureUser(),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
2 changes: 1 addition & 1 deletion API/Backend/Users/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const router = require("./routes/users");
let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use("/API/users", s.checkHeadersCodeInjection, router);
s.app.use(s.ROOT_PATH + "/API/users", s.checkHeadersCodeInjection, router);
},
//Once the server starts
onceStarted: (s) => {},
Expand Down
7 changes: 6 additions & 1 deletion API/Backend/Utils/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ const router = require("./routes/utils");
let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use("/API/utils", s.ensureUser(), s.setContentType, router);
s.app.use(
s.ROOT_PATH + "/API/utils",
s.ensureUser(),
s.setContentType,
router
);
},
//Once the server starts
onceStarted: (s) => {},
Expand Down
8 changes: 6 additions & 2 deletions API/Backend/Webhooks/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ const routerTestWebhooks = require("./routes/testwebhooks");
let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use("/API/webhooks", s.checkHeadersCodeInjection, routerWebhooks);
s.app.use(
s.ROOT_PATH + "/API/webhooks",
s.checkHeadersCodeInjection,
routerWebhooks
);
if (process.env.NODE_ENV === "development") {
s.app.use(
"/API/testwebhooks",
s.ROOT_PATH + "/API/testwebhooks",
s.checkHeadersCodeInjection,
routerTestWebhooks
);
Expand Down
8 changes: 4 additions & 4 deletions API/Backend/setupTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const router = require("./routes/your_router");

let setup = {
//Once the app initializes
onceInit: s => {},
onceInit: (s) => {},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {},
envs: [{ name: "ENV_VAR", description: "", required: false, private: false }]
onceSynced: (s) => {},
envs: [{ name: "ENV_VAR", description: "", required: false, private: false }],
};

module.exports = setup;
4 changes: 4 additions & 0 deletions configuration/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function getClientEnvironment(publicUrl) {
// This should only be used as an escape hatch. Normally you would put
// images into the `src` and `import` them in code to get their paths.
PUBLIC_URL: publicUrl,
ROOT_PATH:
(process.env.NODE_ENV || "development") === "development"
? ""
: process.env.ROOT_PATH || "",
// We support configuring the sockjs pathname during development.
// These settings let a developer run multiple simultaneous projects.
// They are used as the connection `hostname`, `pathname` and `port`
Expand Down
2 changes: 1 addition & 1 deletion configuration/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = function (webpackEnv) {
loader: "string-replace-loader",
options: {
search: /url\(\/public\//g,
replace: `url(${process.env.PUBLIC_URL}/`,
replace: `url(${process.env.ROOT_PATH}/public/`,
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
mmgisglobal.CLEARANCE_NUMBER = "#{CLEARANCE_NUMBER}";
mmgisglobal.HOSTS = "#{HOSTS}";
mmgisglobal.PORT = "#{PORT}";
mmgisglobal.ROOT_PATH = "#{ROOT_PATH}";
mmgisglobal.ENABLE_MMGIS_WEBSOCKETS = "#{ENABLE_MMGIS_WEBSOCKETS}";
mmgisglobal.THIRD_PARTY_COOKIES = "#{THIRD_PARTY_COOKIES}";
break;
Expand All @@ -348,6 +349,7 @@
mmgisglobal.FORCE_CONFIG_PATH = null;
mmgisglobal.CLEARANCE_NUMBER = "%CLEARANCE_NUMBER%";
mmgisglobal.PORT = "%PORT%";
mmgisglobal.ROOT_PATH = "%ROOT_PATH%";
mmgisglobal.ENABLE_MMGIS_WEBSOCKETS = "%ENABLE_MMGIS_WEBSOCKETS%";
mmgisglobal.THIRD_PARTY_COOKIES = "#{THIRD_PARTY_COOKIES}";
// eslint-disable-next-line
Expand Down
113 changes: 73 additions & 40 deletions run/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const isDevEnv = process.env.NODE_ENV === "development";
//Username to use when not logged in
const guestUsername = "guest";

const ROOT_PATH = isDevEnv ? "" : process.env.ROOT_PATH || "";

const rootDir = `${__dirname}/..`;

///////////////////////////
Expand Down Expand Up @@ -386,6 +388,7 @@ let s = {
swaggerUi,
useSwaggerSchema,
permissions,
ROOT_PATH,
};

// Trust first proxy
Expand Down Expand Up @@ -506,48 +509,72 @@ setups.getBackendSetups(function (setups) {

// STATICS

app.use("/build", ensureUser(), express.static(path.join(rootDir, "/build")));
app.use(
"/documentation",
`${ROOT_PATH}/build`,
ensureUser(),
express.static(path.join(rootDir, "/build"))
);
app.use(
`${ROOT_PATH}/documentation`,
express.static(path.join(rootDir, "/documentation"))
);
app.use("/docs/helps", express.static(path.join(rootDir, "/docs/helps")));
app.use("/README.md", express.static(path.join(rootDir, "/README.md")));
app.use("/config/login", express.static(path.join(rootDir, "/config/login")));
app.use(
"/config/css",
`${ROOT_PATH}/docs/helps`,
express.static(path.join(rootDir, "/docs/helps"))
);
app.use(
`${ROOT_PATH}/README.md`,
express.static(path.join(rootDir, "/README.md"))
);
app.use(
`${ROOT_PATH}/config/login`,
express.static(path.join(rootDir, "/config/login"))
);
app.use(
`${ROOT_PATH}/config/css`,
ensureUser(),
express.static(path.join(rootDir, "/config/css"))
);
app.use(
"/config/js",
`${ROOT_PATH}/config/js`,
ensureUser(),
express.static(path.join(rootDir, "/config/js"))
);
app.use(
"/config/pre",
`${ROOT_PATH}/config/pre`,
ensureUser(),
express.static(path.join(rootDir, "/config/pre"))
);
app.use(
"/config/fonts",
`${ROOT_PATH}/config/fonts`,
ensureUser(),
express.static(path.join(rootDir, "/config/fonts"))
);

if (process.argv.includes("--with_examples"))
app.use("/examples", express.static(path.join(rootDir, "/examples")));
app.use("/public", express.static(path.join(rootDir, "/public")));
app.use(
`${ROOT_PATH}/examples`,
express.static(path.join(rootDir, "/examples"))
);
app.use(`${ROOT_PATH}/public`, express.static(path.join(rootDir, "/public")));
app.use(
"/Missions",
`${ROOT_PATH}/Missions`,
ensureUser(),
middleware.missions(),
express.static(path.join(rootDir, "/Missions"))
);

if (isDevEnv) {
app.use("/css", ensureUser(), express.static(path.join(rootDir, "/css")));
app.use("/src", ensureUser(), express.static(path.join(rootDir, "/src")));
app.use(
`${ROOT_PATH}/css`,
ensureUser(),
express.static(path.join(rootDir, "/css"))
);
app.use(
`${ROOT_PATH}/src`,
ensureUser(),
express.static(path.join(rootDir, "/src"))
);
}

// Disable for now
Expand Down Expand Up @@ -686,32 +713,38 @@ setups.getBackendSetups(function (setups) {
// passing to it an array of LDAP group names (which were loaded
// from the permissions.json file at the top of the file).

app.get("/", ensureUser(), ensureGroup(permissions.users), (req, res) => {
let user = guestUsername;
if (process.env.AUTH === "csso" || req.user != null) user = req.user;

let permission = "000";
if (process.env.AUTH === "csso") permission = "001";
if (req.session.permission) permission = req.session.permission;

const groups = req.groups ? Object.keys(req.groups) : [];
res.render("../build/index.pug", {
user: user,
permission: permission,
groups: JSON.stringify(groups),
AUTH: process.env.AUTH,
NODE_ENV: process.env.NODE_ENV,
VERSION: packagejson.version,
FORCE_CONFIG_PATH: process.env.FORCE_CONFIG_PATH,
CLEARANCE_NUMBER: process.env.CLEARANCE_NUMBER,
ENABLE_MMGIS_WEBSOCKETS: process.env.ENABLE_MMGIS_WEBSOCKETS,
THIRD_PARTY_COOKIES: process.env.THIRD_PARTY_COOKIES,
PORT: process.env.PORT,
HOSTS: JSON.stringify({
scienceIntent: process.env.SCIENCE_INTENT_HOST,
}),
});
});
app.get(
`${ROOT_PATH}/`,
ensureUser(),
ensureGroup(permissions.users),
(req, res) => {
let user = guestUsername;
if (process.env.AUTH === "csso" || req.user != null) user = req.user;

let permission = "000";
if (process.env.AUTH === "csso") permission = "001";
if (req.session.permission) permission = req.session.permission;

const groups = req.groups ? Object.keys(req.groups) : [];
res.render("../build/index.pug", {
user: user,
permission: permission,
groups: JSON.stringify(groups),
AUTH: process.env.AUTH,
NODE_ENV: process.env.NODE_ENV,
VERSION: packagejson.version,
FORCE_CONFIG_PATH: process.env.FORCE_CONFIG_PATH,
CLEARANCE_NUMBER: process.env.CLEARANCE_NUMBER,
ENABLE_MMGIS_WEBSOCKETS: process.env.ENABLE_MMGIS_WEBSOCKETS,
THIRD_PARTY_COOKIES: process.env.THIRD_PARTY_COOKIES,
PORT: process.env.PORT,
ROOT_PATH: ROOT_PATH,
HOSTS: JSON.stringify({
scienceIntent: process.env.SCIENCE_INTENT_HOST,
}),
});
}
);
}
if (err) {
logger("infrastructure_error", "MMGIS did not start!", "server");
Expand Down
Loading

0 comments on commit 4061387

Please sign in to comment.