diff --git a/package.json b/package.json index f9e1dd4..d3b2b96 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "intmax2", "blockchain", "function", - "api" + "api", + "token" ], "engines": { "node": ">=20.0.0", diff --git a/packages/indexer/README.md b/packages/indexer/README.md index 2fed87c..84acf97 100644 --- a/packages/indexer/README.md +++ b/packages/indexer/README.md @@ -27,5 +27,10 @@ curl http://localhost:3000/v1/health | jq curl -X GET 'http://localhost:3000/v1/indexer/builders' | jq curl -X GET 'http://localhost:3000/v1/indexer/builders/meta' | jq curl -X GET 'http://localhost:3000/v1/indexer/builders/registration/0x...' | jq + +# for proxy curl -X GET 'http://localhost:3000/v1/proxy/meta' | jq + +# time +curl -X GET 'http://localhost:3000/v1/time' | jq ``` diff --git a/packages/indexer/src/controllers/time.controller.ts b/packages/indexer/src/controllers/time.controller.ts new file mode 100644 index 0000000..860ac33 --- /dev/null +++ b/packages/indexer/src/controllers/time.controller.ts @@ -0,0 +1,7 @@ +import type { Context } from "hono"; +import * as timeService from "../services/time.service"; + +export const getTime = (c: Context) => { + const result = timeService.getTime(); + return c.json(result); +}; diff --git a/packages/indexer/src/routes/index.ts b/packages/indexer/src/routes/index.ts index e8d1a3b..5b6d0ef 100644 --- a/packages/indexer/src/routes/index.ts +++ b/packages/indexer/src/routes/index.ts @@ -1,6 +1,7 @@ import { BASE_PATH, healthRoute } from "@intmax2-function/shared"; import { route as indexerRoute } from "./indexer.route"; import { route as proxyRoute } from "./proxy.route"; +import { route as timeRoute } from "./time.route"; export const routes = [ { @@ -15,4 +16,8 @@ export const routes = [ path: `${BASE_PATH}/proxy`, route: proxyRoute, }, + { + path: `${BASE_PATH}/time`, + route: timeRoute, + }, ]; diff --git a/packages/indexer/src/routes/time.route.ts b/packages/indexer/src/routes/time.route.ts new file mode 100644 index 0000000..759c792 --- /dev/null +++ b/packages/indexer/src/routes/time.route.ts @@ -0,0 +1,6 @@ +import { Hono } from "hono"; +import * as timeController from "../controllers/time.controller"; + +export const route = new Hono(); + +route.get("/", timeController.getTime); diff --git a/packages/indexer/src/services/time.service.ts b/packages/indexer/src/services/time.service.ts new file mode 100644 index 0000000..f4155e3 --- /dev/null +++ b/packages/indexer/src/services/time.service.ts @@ -0,0 +1,35 @@ +export const getTime = () => { + const now = new Date(); + + const year = now.getUTCFullYear(); + const month = now.getUTCMonth() + 1; + const day = now.getUTCDate(); + const hour = now.getUTCHours(); + const minute = now.getUTCMinutes(); + const seconds = now.getUTCSeconds(); + const milliSeconds = now.getUTCMilliseconds(); + + const dateTime = now.toISOString(); + const date = `${month.toString().padStart(2, "0")}/${day.toString().padStart(2, "0")}/${year}`; + const time = `${hour.toString().padStart(2, "0")}:${minute.toString().padStart(2, "0")}`; + const dayOfWeek = now.toLocaleDateString("en-US", { + weekday: "long", + timeZone: "UTC", + }); + + return { + year, + month, + day, + hour, + minute, + seconds, + milliSeconds, + dateTime, + date, + time, + timeZone: "UTC", + dayOfWeek, + dstActive: false, + }; +};