From f0b05854e85da3120123633ecd7a09c0a19fae5b Mon Sep 17 00:00:00 2001 From: Darwin <77340894+charmful0x@users.noreply.github.com> Date: Sat, 11 Mar 2023 20:40:57 +0100 Subject: [PATCH 1/2] feat: refactor code --- src/api.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) 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 From bb159076148291e846b30e07e145f717d91f9f1b Mon Sep 17 00:00:00 2001 From: Darwin <77340894+charmful0x@users.noreply.github.com> Date: Sat, 11 Mar 2023 20:41:26 +0100 Subject: [PATCH 2/2] feat: v0.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",