diff options
author | Bob Zeleznik <zzzman@gmail.com> | 2020-03-17 01:12:21 -0400 |
---|---|---|
committer | Bob Zeleznik <zzzman@gmail.com> | 2020-03-17 01:12:21 -0400 |
commit | e9a16afa46af3ecec0bd7b58f9ca13b85d62a860 (patch) | |
tree | 47b740efe7f800b1de833015ed4e610796da1f3c /src | |
parent | 1230b4a3307725c5e0eb4daae991b2db5f4d1c96 (diff) |
fixed up route handling for relative paths. changed search to dashsearch for server request.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/SearchUtil.ts | 6 | ||||
-rw-r--r-- | src/server/ApiManagers/SearchManager.ts | 2 | ||||
-rw-r--r-- | src/server/RouteManager.ts | 36 | ||||
-rw-r--r-- | src/server/index.ts | 3 |
4 files changed, 30 insertions, 17 deletions
diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts index 2d9c807dd..b597f1e07 100644 --- a/src/client/util/SearchUtil.ts +++ b/src/client/util/SearchUtil.ts @@ -34,7 +34,7 @@ export namespace SearchUtil { export function Search(query: string, returnDocs: false, options?: SearchParams): Promise<IdSearchResult>; export async function Search(query: string, returnDocs: boolean, options: SearchParams = {}) { query = query || "*"; //If we just have a filter query, search for * as the query - const rpquery = Utils.prepend("/search"); + const rpquery = Utils.prepend("/dashsearch"); const gotten = await rp.get(rpquery, { qs: { ...options, q: query } }); const result: IdSearchResult = gotten.startsWith("<") ? { ids: [], docs: [], numFound: 0, lines: [] } : JSON.parse(gotten); if (!returnDocs) { @@ -52,7 +52,7 @@ export namespace SearchUtil { const newLines: string[][] = []; await Promise.all(fileids.map(async (tr: string, i: number) => { const docQuery = "fileUpload_t:" + tr.substr(0, 7); //If we just have a filter query, search for * as the query - const docResult = JSON.parse(await rp.get(Utils.prepend("/search"), { qs: { ...options, q: docQuery } })); + const docResult = JSON.parse(await rp.get(Utils.prepend("/dashsearch"), { qs: { ...options, q: docQuery } })); newIds.push(...docResult.ids); newLines.push(...docResult.ids.map((dr: any) => txtresult.lines[i])); })); @@ -121,7 +121,7 @@ export namespace SearchUtil { export async function GetAllDocs() { const query = "*"; - const response = await rp.get(Utils.prepend('/search'), { + const response = await rp.get(Utils.prepend('/dashsearch'), { qs: { start: 0, rows: 10000, q: query }, diff --git a/src/server/ApiManagers/SearchManager.ts b/src/server/ApiManagers/SearchManager.ts index be17c3105..5f7d1cf6d 100644 --- a/src/server/ApiManagers/SearchManager.ts +++ b/src/server/ApiManagers/SearchManager.ts @@ -61,7 +61,7 @@ export class SearchManager extends ApiManager { register({ method: Method.GET, - subscription: "/search", + subscription: "/dashsearch", secureHandler: async ({ req, res }) => { const solrQuery: any = {}; ["q", "fq", "start", "rows", "hl", "hl.fl"].forEach(key => solrQuery[key] = req.query[key]); diff --git a/src/server/RouteManager.ts b/src/server/RouteManager.ts index d8265582e..c88f3bb51 100644 --- a/src/server/RouteManager.ts +++ b/src/server/RouteManager.ts @@ -79,6 +79,7 @@ export default class RouteManager { } } + static routes: string[] = []; /** * * @param initializer @@ -86,11 +87,18 @@ export default class RouteManager { addSupervisedRoute = (initializer: RouteInitializer): void => { const { method, subscription, secureHandler, publicHandler, errorHandler } = initializer; + typeof (initializer.subscription) === "string" && RouteManager.routes.push(initializer.subscription); + initializer.subscription instanceof RouteSubscriber && RouteManager.routes.push(initializer.subscription.root); + initializer.subscription instanceof Array && initializer.subscription.map(sub => { + typeof (sub) === "string" && RouteManager.routes.push(sub); + sub instanceof RouteSubscriber && RouteManager.routes.push(sub.root); + }); const isRelease = this._isRelease; let redirected = ""; const supervised = async (req: Request, res: Response) => { let { user } = req; const { originalUrl: target } = req; + console.log("TARGET: " + target); if (process.env.DB === "MEM" && !user) { user = { id: "guest", email: "", userDocumentId: "guestDocId" }; } @@ -126,26 +134,30 @@ export default class RouteManager { const original = url.replace(start, ""); const theurl = original.match(/http[s]?:\/\/[^\/]*/)![0]; const newdirect = start + encodeURIComponent(theurl + target); - if (newdirect !== redirected) { - redirected = newdirect; - console.log("redirect relative path: " + (theurl + target)); - res.redirect(redirected); - } + console.log("REDIRECT: " + (theurl + target)); + res.redirect(newdirect); } - else { - if (target.startsWith("/doc/")) { - !res.headersSent && setTimeout(() => { + else if (!res.headersSent) { + const which2 = RouteManager.routes.findIndex(r => (r !== "/" || r === target) && target.startsWith(r)); + const which = Array.from(registered.keys()).findIndex(r => (r !== "/" || r === target) && target.startsWith(r)); + console.log("WHICH = " + (which === -1 ? "" : Array.from(registered.keys())[which])); + if (which !== -1) { + setTimeout(() => { + console.log("handled:" + target); if (!res.headersSent) { - res.redirect("/login"); console.log(red(`Initiating fallback for ${target}. Please remove dangling promise from route handler`)); const warning = `request to ${target} fell through - this is a fallback response`; res.send({ warning }); } }, 1000); - } else { - const warning = `request to ${target} fell through - this is a fallback response`; - res.send({ warning }); } + else { + console.log("unhandled:" + target); + res.end(); + } + } else { + console.log("pre-sent:" + target); + res.end(); } }; const subscribe = (subscriber: RouteSubscriber | string) => { diff --git a/src/server/index.ts b/src/server/index.ts index c4c05157a..def36e922 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -117,7 +117,8 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }: addSupervisedRoute({ method: Method.GET, subscription: "/*", - secureHandler: ({ res }) => { } + secureHandler: ({ res }) => { + } }); logRegistrationOutcome(); |