Rename express/ to backend/ and update references
Update paths in sync.sh, master/main.go, and CLAUDE.md to reflect the directory rename. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
148
backend/routes.ts
Normal file
148
backend/routes.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
/// <reference lib="dom" />
|
||||
|
||||
import nunjucks from "nunjucks";
|
||||
import { DateTime } from "ts-luxon";
|
||||
import { authRoutes } from "./diachron/auth/routes";
|
||||
import { routes as basicRoutes } from "./diachron/basic/routes";
|
||||
import { contentTypes } from "./diachron/content-types";
|
||||
import { core } from "./diachron/core";
|
||||
import { multiHandler } from "./diachron/handlers";
|
||||
import { httpCodes } from "./diachron/http-codes";
|
||||
import type { Call, Result, Route } from "./diachron/types";
|
||||
|
||||
// FIXME: Obviously put this somewhere else
|
||||
const okText = (result: string): Result => {
|
||||
const code = httpCodes.success.OK;
|
||||
|
||||
const retval: Result = {
|
||||
code,
|
||||
result,
|
||||
contentType: contentTypes.text.plain,
|
||||
};
|
||||
|
||||
return retval;
|
||||
};
|
||||
|
||||
const routes: Route[] = [
|
||||
...authRoutes,
|
||||
basicRoutes.home,
|
||||
basicRoutes.hello,
|
||||
basicRoutes.login,
|
||||
basicRoutes.logout,
|
||||
{
|
||||
path: "/slow",
|
||||
methods: ["GET"],
|
||||
handler: async (_call: Call): Promise<Result> => {
|
||||
console.log("starting slow request");
|
||||
|
||||
await core.misc.sleep(2);
|
||||
|
||||
console.log("finishing slow request");
|
||||
const retval = okText("that was slow");
|
||||
|
||||
return retval;
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/list",
|
||||
methods: ["GET"],
|
||||
handler: async (_call: Call): Promise<Result> => {
|
||||
const code = httpCodes.success.OK;
|
||||
const lr = (rr: Route[]) => {
|
||||
const ret = rr.map((r: Route) => {
|
||||
return r.path;
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
const rrr = lr(routes);
|
||||
|
||||
const template = `
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<ul>
|
||||
{% for route in rrr %}
|
||||
<li><a href="{{ route }}">{{ route }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
const result = nunjucks.renderString(template, { rrr });
|
||||
|
||||
const _listing = lr(routes).join(", ");
|
||||
return {
|
||||
code,
|
||||
result,
|
||||
contentType: contentTypes.text.html,
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/whoami",
|
||||
methods: ["GET"],
|
||||
handler: async (call: Call): Promise<Result> => {
|
||||
const me = call.session.getUser();
|
||||
const template = `
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
{{ me }}
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
const result = nunjucks.renderString(template, { me });
|
||||
|
||||
return {
|
||||
code: httpCodes.success.OK,
|
||||
contentType: contentTypes.text.html,
|
||||
result,
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/ok",
|
||||
methods: ["GET", "POST", "PUT"],
|
||||
handler: multiHandler,
|
||||
},
|
||||
{
|
||||
path: "/alsook",
|
||||
methods: ["GET"],
|
||||
handler: async (_req): Promise<Result> => {
|
||||
const code = httpCodes.success.OK;
|
||||
return {
|
||||
code,
|
||||
result: "it is also ok",
|
||||
contentType: contentTypes.text.plain,
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/time",
|
||||
methods: ["GET"],
|
||||
handler: async (_req): Promise<Result> => {
|
||||
const now = DateTime.now();
|
||||
const template = `
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
{{ now }}
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
const result = nunjucks.renderString(template, { now });
|
||||
|
||||
return {
|
||||
code: httpCodes.success.OK,
|
||||
contentType: contentTypes.text.html,
|
||||
result,
|
||||
};
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export { routes };
|
||||
Reference in New Issue
Block a user