Skip to content

Commit

Permalink
pass app settings to mkurl endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed Nov 23, 2022
1 parent 6566622 commit 4e91a48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function createApp(serverSettings: ServerSettings, settingsManage
attachRouter("/sources", sourcesRouter(settingsManager.sourcesGetter));
attachRouter("/plywood", plywoodRouter(settingsManager));
attachRouter("/plyql", plyqlRouter(settingsManager.sourcesGetter));
attachRouter("/mkurl", mkurlRouter(settingsManager.sourcesGetter));
attachRouter("/mkurl", mkurlRouter(settingsManager.appSettings, settingsManager.sourcesGetter));
attachRouter("/shorten", shortenRouter(settingsManager.appSettings, isTrustedProxy));

attachRouter("/", turniloRouter(settingsManager.appSettings, () => settingsManager.getTimekeeper(), version));
Expand Down
3 changes: 2 additions & 1 deletion src/server/routes/mkurl/mkurl.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as bodyParser from "body-parser";
import express from "express";
import { $ } from "plywood";
import supertest from "supertest";
import { appSettings } from "../../../common/models/app-settings/app-settings.fixtures";
import { wikiSourcesWithExecutor } from "../../../common/models/sources/sources.fixtures";
import { UrlHashConverterFixtures } from "../../../common/utils/url-hash-converter/url-hash-converter.fixtures";
import { mkurlRouter } from "./mkurl";
Expand All @@ -29,7 +30,7 @@ let app = express();

app.use(bodyParser.json());

app.use(mkurlPath, mkurlRouter(() => Promise.resolve(wikiSourcesWithExecutor)));
app.use(mkurlPath, mkurlRouter(appSettings, () => Promise.resolve(wikiSourcesWithExecutor)));

describe("mkurl router", () => {
it("gets a simple url back", (testComplete: any) => {
Expand Down
10 changes: 8 additions & 2 deletions src/server/routes/mkurl/mkurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

import { Request, Response, Router } from "express";
import { deserialize } from "../../../client/deserializers/app-settings";
import { AppSettings, ClientAppSettings, serialize } from "../../../common/models/app-settings/app-settings";
import { ClientDataCube } from "../../../common/models/data-cube/data-cube";
import { isQueryable } from "../../../common/models/data-cube/queryable-data-cube";
import { Essence } from "../../../common/models/essence/essence";
Expand All @@ -24,7 +26,11 @@ import { urlHashConverter } from "../../../common/utils/url-hash-converter/url-h
import { definitionConverters, ViewDefinitionVersion } from "../../../common/view-definitions";
import { SourcesGetter } from "../../utils/settings-manager/settings-manager";

export function mkurlRouter(sourcesGetter: SourcesGetter) {
function convertAppSettings(appSettings: AppSettings): ClientAppSettings {
return deserialize(serialize(appSettings));
}

export function mkurlRouter(appSettings: AppSettings, sourcesGetter: SourcesGetter) {

const router = Router();

Expand Down Expand Up @@ -79,7 +85,7 @@ export function mkurlRouter(sourcesGetter: SourcesGetter) {
};

try {
essence = definitionConverter.fromViewDefinition(viewDefinition, clientDataCube);
essence = definitionConverter.fromViewDefinition(viewDefinition, clientDataCube, convertAppSettings(appSettings));
} catch ({ message }) {
res.status(400).send({ error: "invalid viewDefinition object", message });
return;
Expand Down

0 comments on commit 4e91a48

Please sign in to comment.