Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules foundations #669

Merged
merged 9 commits into from
Nov 10, 2020
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
"test-watcher": "mocha --require ./test/setup/mocha.js --watch --watch-extensions ts,tsx",
"start": "./bin/turnilo",
"start:dev": "NODE_ENV=dev-hmr ./bin/turnilo",
"build": "npm run clean && npm run tsc -- -p src/server/tsconfig.json && webpack --config config/webpack.prod.js",
"build:dev": "npm run clean && npm run tsc -- -p src/server/tsconfig.json",
"dev": "npm run clean && npm run tsc -- -p tsconfig.json -w --pretty",
"start:examples": "npm run start -- --examples",
"start:dev:examples": "npm run start:dev -- --examples",
"build:client": "webpack --config config/webpack.prod.js",
"build:server": "npm run tsc -- -p src/server/tsconfig.json ",
"build": "npm-run-all -s clean build:server build:client",
"clean": "rimraf build/*",
"tsc": "tsc",
"lint": "npm-run-all -p lint:*",
"lint:ts": "tslint -p . --format verbose",
"lint:sass": "sass-lint -v",
"start:examples": "npm run start -- --examples",
"start:dev:examples": "npm run start:dev -- --examples",
"e2e": "start-server-and-test start:examples http://localhost:9090/health/ready 'cypress run'",
"e2e:dev": "cypress open",
"check": "npm-run-all -c -p lint test build e2e"
Expand Down
36 changes: 17 additions & 19 deletions src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Handler, Request, Response, Router } from "express";
import { hsts } from "helmet";
import * as path from "path";
import { LOGGER } from "../common/logger/logger";
import { AUTH, SERVER_SETTINGS, SETTINGS_MANAGER, VERSION } from "./config";
import { SERVER_SETTINGS, SETTINGS_MANAGER, VERSION } from "./config";
import { livenessRouter } from "./routes/liveness/liveness";
import { mkurlRouter } from "./routes/mkurl/mkurl";
import { plyqlRouter } from "./routes/plyql/plyql";
Expand Down Expand Up @@ -65,6 +65,20 @@ if (SERVER_SETTINGS.getStrictTransportSecurity() === "always") {
}));
}

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

if (SERVER_SETTINGS.getIframe() === "deny") {
app.use((req: Request, res: Response, next: Function) => {
res.setHeader("X-Frame-Options", "DENY");
res.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
next();
});
}

// TODO: plugins go here

// TODO: after plugins
// development HMR
if (app.get("env") === "dev-hmr") {
// add hot module replacement
Expand Down Expand Up @@ -93,16 +107,8 @@ if (app.get("env") === "dev-hmr") {
attachRouter("/", express.static(path.join(__dirname, "../../build/public")));
attachRouter("/", express.static(path.join(__dirname, "../../assets")));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

const settingsGetter: SettingsGetter = opts => SETTINGS_MANAGER.getSettings(opts);

// Auth
if (AUTH) {
app.use(AUTH);
}

attachRouter(SERVER_SETTINGS.getReadinessEndpoint(), readinessRouter(settingsGetter));
attachRouter(SERVER_SETTINGS.getLivenessEndpoint(), livenessRouter);

Expand All @@ -112,16 +118,8 @@ attachRouter("/plyql", plyqlRouter(settingsGetter));
attachRouter("/mkurl", mkurlRouter(settingsGetter));
attachRouter("/shorten", shortenRouter(settingsGetter, isTrustedProxy));

// View routes
if (SERVER_SETTINGS.getIframe() === "deny") {
app.use((req: Request, res: Response, next: Function) => {
res.setHeader("X-Frame-Options", "DENY");
res.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
next();
});
}

attachRouter("/", turniloRouter(settingsGetter, VERSION));
const freshSettingsGetter: SettingsGetter = opts => SETTINGS_MANAGER.getFreshSettings(opts);
attachRouter("/", turniloRouter(freshSettingsGetter, VERSION));

// Catch 404 and redirect to /
app.use((req: Request, res: Response) => {
Expand Down
Loading