tangled
alpha
login
or
join now
danabra.mov
/
statusphere-react
forked from
samuel.fm/statusphere-react
0
fork
atom
the statusphere demo reworked into a vite/react app in a monorepo
0
fork
atom
overview
issues
pulls
pipelines
tidy router
dholms
2 years ago
ef772a14
9990f3e3
+18
-15
3 changed files
expand all
collapse all
unified
split
src
router.ts
routes.ts
server.ts
+15
src/router.ts
···
1
1
+
import express from "express";
2
2
+
import { Post } from "#/db";
3
3
+
4
4
+
const router = express.Router();
5
5
+
6
6
+
router.get("/", async (req, res) => {
7
7
+
const posts = await Post.findAll({
8
8
+
order: [["createdAt", "DESC"]],
9
9
+
limit: 10,
10
10
+
});
11
11
+
const texts = posts.map((p) => p.dataValues.text);
12
12
+
res.json(texts);
13
13
+
});
14
14
+
15
15
+
export default router;
-13
src/routes.ts
···
1
1
-
import type express from "express";
2
2
-
import { Post } from "#/db";
3
3
-
4
4
-
export const addRoutes = (app: express.Application) => {
5
5
-
app.get("/", async (req, res) => {
6
6
-
const posts = await Post.findAll({
7
7
-
order: [["createdAt", "DESC"]],
8
8
-
limit: 10,
9
9
-
});
10
10
-
const texts = posts.map((p) => p.dataValues.text);
11
11
-
res.json(texts);
12
12
-
});
13
13
-
};
+3
-2
src/server.ts
···
11
11
import { env } from "#/common/utils/envConfig";
12
12
import { Database } from "#/db";
13
13
import { Firehose } from "#/firehose";
14
14
-
import { addRoutes } from "#/routes";
14
14
+
import router from "#/router";
15
15
16
16
export class Server {
17
17
constructor(
···
45
45
// Request logging
46
46
app.use(requestLogger);
47
47
48
48
-
addRoutes(app);
48
48
+
// Routes
49
49
+
app.use(router);
49
50
50
51
// Error handlers
51
52
app.use(errorHandler());