Skip to content

Commit

Permalink
Merge pull request #3 from decentldotland/staging
Browse files Browse the repository at this point in the history
feat: refactor code to Express API
  • Loading branch information
charmful0x authored Mar 11, 2023
2 parents 15559ee + bb15907 commit 2e481eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
34 changes: 32 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -15,5 +47,3 @@ async function polling() {
await sleep(5);
}
}

polling();

0 comments on commit 2e481eb

Please sign in to comment.