Scratch space for learning atproto app development

tidy router

dholms ef772a14 9990f3e3

Changed files
+18 -15
src
+15
src/router.ts
···
+
import express from "express";
+
import { Post } from "#/db";
+
+
const router = express.Router();
+
+
router.get("/", async (req, res) => {
+
const posts = await Post.findAll({
+
order: [["createdAt", "DESC"]],
+
limit: 10,
+
});
+
const texts = posts.map((p) => p.dataValues.text);
+
res.json(texts);
+
});
+
+
export default router;
-13
src/routes.ts
···
-
import type express from "express";
-
import { Post } from "#/db";
-
-
export const addRoutes = (app: express.Application) => {
-
app.get("/", async (req, res) => {
-
const posts = await Post.findAll({
-
order: [["createdAt", "DESC"]],
-
limit: 10,
-
});
-
const texts = posts.map((p) => p.dataValues.text);
-
res.json(texts);
-
});
-
};
+3 -2
src/server.ts
···
import { env } from "#/common/utils/envConfig";
import { Database } from "#/db";
import { Firehose } from "#/firehose";
-
import { addRoutes } from "#/routes";
+
import router from "#/router";
export class Server {
constructor(
···
// Request logging
app.use(requestLogger);
-
addRoutes(app);
+
// Routes
+
app.use(router);
// Error handlers
app.use(errorHandler());