diff --git a/express/app.ts b/express/app.ts index 862f59f..417ad99 100644 --- a/express/app.ts +++ b/express/app.ts @@ -76,9 +76,8 @@ routes.forEach((route: Route, _idx: number, _allRoutes: Route[]) => { }; try { - const retval = await runWithContext( - { user: auth.user }, - () => route.handler(req), + const retval = await runWithContext({ user: auth.user }, () => + route.handler(req), ); return retval; } catch (error) { @@ -117,7 +116,12 @@ async function handler( const method = await methodParser.parseAsync(req.method); const byMethod = processedRoutes[method]; - console.log("DEBUG: req.path =", JSON.stringify(req.path), "method =", method); + console.log( + "DEBUG: req.path =", + JSON.stringify(req.path), + "method =", + method, + ); for (const [_idx, pr] of byMethod.entries()) { const match = pr.matcher(req.path); console.log("DEBUG: trying pattern, match result =", match); diff --git a/express/basic/routes.ts b/express/basic/routes.ts index 4c207fc..a27b6cd 100644 --- a/express/basic/routes.ts +++ b/express/basic/routes.ts @@ -1,11 +1,9 @@ import { DateTime } from "ts-luxon"; +import { services } from "../services"; import type { Call, Result, Route } from "../types"; import { html, render } from "../util"; import { loginRoute } from "./login"; -import { services } from '../services'; - - const routes: Record = { hello: { path: "/hello", @@ -18,17 +16,17 @@ const routes: Record = { }, }, home: { - path:'/', - methods:['GET'], - handler:async(_call:Call): Promise => { - const auth = services.auth - const me = services.session.getUser() + path: "/", + methods: ["GET"], + handler: async (_call: Call): Promise => { + const auth = services.auth; + const me = services.session.getUser(); - const email = me.toString() - const c = await render('basic/home',{email}) + const email = me.toString(); + const c = await render("basic/home", { email }); - return html(c) - } + return html(c); + }, }, login: loginRoute, }; diff --git a/express/mgmt/add-user.ts b/express/mgmt/add-user.ts index 892787f..4dbc854 100644 --- a/express/mgmt/add-user.ts +++ b/express/mgmt/add-user.ts @@ -1,8 +1,8 @@ // add-user.ts // Management command to create users from the command line -import { pool, PostgresAuthStore } from "../database"; import { hashPassword } from "../auth/password"; +import { PostgresAuthStore, pool } from "../database"; async function main(): Promise { const args = process.argv.slice(2); @@ -51,7 +51,9 @@ async function main(): Promise { // Optionally activate user immediately if (makeActive) { await store.updateUserEmailVerified(user.id); - console.log(`Created and activated user: ${user.email} (${user.id})`); + console.log( + `Created and activated user: ${user.email} (${user.id})`, + ); } else { console.log(`Created user: ${user.email} (${user.id})`); console.log(" Status: pending (use --active to create as active)"); diff --git a/express/util.ts b/express/util.ts index 78e9d9b..c80b7a7 100644 --- a/express/util.ts +++ b/express/util.ts @@ -3,7 +3,7 @@ import nunjucks from "nunjucks"; import { contentTypes } from "./content-types"; import { executionContext } from "./execution-context"; import { httpCodes } from "./http-codes"; -import type { Result, RedirectResult } from "./types"; +import type { RedirectResult, Result } from "./types"; // FIXME: Handle the error here const loadFile = async (path: string): Promise => { @@ -18,7 +18,7 @@ const render = async (path: string, ctx?: object): Promise => { const template = await loadFile(fullPath); - const c = ctx===undefined ? {} : ctx; + const c = ctx === undefined ? {} : ctx; const retval = nunjucks.renderString(template, c); @@ -26,7 +26,7 @@ const render = async (path: string, ctx?: object): Promise => { }; const html = (payload: string): Result => { - const retval: Result = { + const retval: Result = { code: httpCodes.success.OK, result: payload, contentType: contentTypes.text.html,