Skip to content

Commit 9d18157

Browse files
authored
Upgrades the rss plugin to parse out date object and use health check (#19)
* upgrades the rss plugin to parse out date object and use health check * fmt
1 parent 4346b34 commit 9d18157

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

packages/rss/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curatedotfun/rss",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "RSS plugin for curatedotfun",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

packages/rss/service/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
handleRawJson,
1111
handleGetItems,
1212
handleAddItem,
13+
handleHealth,
1314
} from "./routes.js";
1415
import { authenticate } from "./middleware.js";
1516
import { initializeFeed } from "./storage.js";
@@ -48,6 +49,7 @@ app.use("/api/*", authenticate);
4849

4950
// Register routes
5051
app.get("/", handleRoot);
52+
app.get("/health", handleHealth);
5153
app.get("/rss.xml", handleRss);
5254
app.get("/atom.xml", handleAtom);
5355
app.get("/feed.json", handleJsonFeed);

packages/rss/service/src/routes.ts

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ import { addItem, getItems } from "./storage.js";
55
import { ApiFormat, RssItem } from "./types.js";
66
import { sanitize } from "./utils.js";
77

8+
/**
9+
* Health check endpoint
10+
*/
11+
export async function handleHealth(c: Context): Promise<Response> {
12+
return c.json(
13+
{
14+
status: "ok",
15+
timestamp: new Date().toISOString(),
16+
service: "rss-service",
17+
},
18+
200,
19+
);
20+
}
21+
822
/**
923
* Health check and redirect to preferred format
1024
*/

packages/rss/src/index.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default class RssPlugin
132132

133133
// Check if service is running with a health check
134134
try {
135-
const healthCheckResponse = await fetch(`${this.serviceUrl}/`, {
135+
const healthCheckResponse = await fetch(`${this.serviceUrl}/health`, {
136136
method: "GET",
137137
});
138138

@@ -245,6 +245,16 @@ export default class RssPlugin
245245
}
246246

247247
try {
248+
// Convert Date objects to ISO strings to ensure proper JSON serialization
249+
const serializedItem = {
250+
...item,
251+
published:
252+
item.published instanceof Date
253+
? item.published.toISOString()
254+
: item.published,
255+
date: item.date instanceof Date ? item.date.toISOString() : item.date,
256+
};
257+
248258
const response = await fetch(`${this.serviceUrl}/api/items`, {
249259
method: "POST",
250260
headers: {
@@ -253,7 +263,7 @@ export default class RssPlugin
253263
? { Authorization: `Bearer ${this.apiSecret}` }
254264
: {}),
255265
},
256-
body: JSON.stringify(item),
266+
body: JSON.stringify(serializedItem),
257267
});
258268

259269
if (!response.ok) {

0 commit comments

Comments
 (0)