31 lines
925 B
JavaScript
31 lines
925 B
JavaScript
import express from "express";
|
|
import session from "express-session";
|
|
import RedisStore from "connect-redis";
|
|
import { createClient } from "redis";
|
|
import { feedQueue } from "./queue.js";
|
|
import { config } from "./config.js";
|
|
const app = express();
|
|
app.use(express.json());
|
|
// Redis client (NO top-level await)
|
|
const redis = createClient({ url: config.redisUrl });
|
|
redis.connect().catch(err => {
|
|
console.error("Redis connection failed:", err);
|
|
});
|
|
app.use(session({
|
|
store: new RedisStore({ client: redis }),
|
|
secret: "dev-secret",
|
|
resave: false,
|
|
saveUninitialized: false
|
|
}));
|
|
// Typed route handlers
|
|
app.get("/health", (_req, res) => {
|
|
res.json({ ok: true });
|
|
});
|
|
app.post("/feeds/:id/poll", async (req, res) => {
|
|
await feedQueue.add("poll-feed", { feedId: req.params.id });
|
|
res.json({ ok: true });
|
|
});
|
|
app.listen(config.port, () => {
|
|
console.log(`API running on port ${config.port}`);
|
|
});
|