MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / createLatestRouter

Function createLatestRouter

server/src/routes/latest.ts:95–406  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93 * Create latest content routes
94 */
95export function createLatestRouter(): {
96 pageRouter: Router;
97 apiRouter: Router;
98} {
99 const pageRouter = Router();
100 const apiRouter = Router();
101
102 // =========================================================================
103 // PAGE ROUTES (mounted at /)
104 // =========================================================================
105
106 // Landing page consolidated into /stories
107 pageRouter.get("/latest", (_req, res) => {
108 res.redirect(301, "/stories");
109 });
110
111 // Legacy redirect from /latest/research to /latest/perspectives
112 pageRouter.get("/latest/research", (req, res) => {
113 res.redirect(301, "/latest/perspectives");
114 });
115
116 // Section detail page
117 pageRouter.get("/latest/:slug", optionalAuth, (req, res) => {
118 serveHtmlWithConfig(req, res, "latest/section.html").catch((err) => {
119 logger.error({ err }, "Error serving latest section page");
120 res.status(500).send("Internal server error");
121 });
122 });
123
124 // =========================================================================
125 // API ROUTES (mounted at /api)
126 // =========================================================================
127
128 /**
129 * GET /api/latest/sections
130 * List all website sections with article counts
131 */
132 apiRouter.get("/latest/sections", async (req: Request, res: Response) => {
133 try {
134 const channels = await getWebsiteChannels();
135
136 // Get article counts for each channel
137 const sections: LatestSection[] = await Promise.all(
138 channels.map(async (channel) => {
139 let articleCount: number;
140
141 // Research section pulls from perspectives table
142 if (channel.website_slug === PERSPECTIVES_SECTION_SLUG) {
143 articleCount = await getResearchArticleCount();
144 } else {
145 // Other sections pull from addie_knowledge
146 const countResult = await query<{ count: string }>(
147 `SELECT COUNT(*) as count
148 FROM addie_knowledge k
149 WHERE k.fetch_status = 'success'
150 AND k.publication_status != 'rejected'
151 AND (
152 $1 = ANY(COALESCE(k.human_routing_override, k.notification_channel_ids))

Callers 1

setupRoutesMethod · 0.85

Calls 6

serveHtmlWithConfigFunction · 0.85
getWebsiteChannelsFunction · 0.85
getResearchArticleCountFunction · 0.85
getChannelByWebsiteSlugFunction · 0.85
decodeHtmlEntitiesFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected