diff --git a/package.json b/package.json index 189d41d..88f8974 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ans-cronjob", - "version": "0.0.1", + "version": "0.0.2", "description": "cronjob for ANS marketplace", "type": "module", "main": "./src/api.js", diff --git a/src/api.js b/src/api.js index 642eacc..776024d 100644 --- a/src/api.js +++ b/src/api.js @@ -1,5 +1,37 @@ +import express from "express"; +import cors from "cors"; + import { getExpiredOrders, cancelOrder, sleep } from "./utils/exm.js"; +const app = express(); + +const port = process.env.PORT || 3000; + +app.use( + cors({ + origin: "*", + }) +); + +app.get("/refresh", async (req, res) => { + try { + const orders = await getExpiredOrders(); + for (const order of orders) { + await cancelOrder(order.id); + } + res.send(orders); + res.end(); + } catch (error) { + res.send({ error: "error oops!" }); + res.end(); + } +}); + +app.listen(port, async () => { + console.log(`listening at PORT: ${port}`); + await polling(); +}); + async function polling() { try { while (true) { @@ -15,5 +47,3 @@ async function polling() { await sleep(5); } } - -polling(); \ No newline at end of file