Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,10 @@ app.get("/api/health", async (req, res) => {

function authMiddleware(req, res, next) {
const key = process.env.CASECOMP_API_KEY;
const sandboxKey = process.env.CASECOMP_SANDBOX_KEY;
if (!key) return next();
const auth = req.headers.authorization;
const query = req.query.key;
const token = auth?.startsWith("Bearer ") ? auth.slice(7) : query;
if (!token || token !== key) {
const token = getRequestToken(req);
if (!token || (token !== key && token !== sandboxKey)) {
return res.status(401).json({ error: "Invalid or missing API key" });
}
next();
Expand Down Expand Up @@ -568,7 +567,15 @@ app.post("/api/alerts", authMiddleware, async (req, res) => {
});

const PORT = process.env.API_PORT || 3000;
app.listen(PORT, () => {
app.listen(PORT, async () => {
console.log(`Casecomp API listening on http://localhost:${PORT}`);
console.log(`Swagger docs: http://localhost:${PORT}/docs`);
if (clientId && clientSecret) {
try {
await getToken();
console.log("eBay OAuth token warmed");
} catch (e) {
console.warn(`eBay token warmup failed: ${e.message}`);
}
}
});