Files
interview-backend/js-hono/src/index.ts
2025-07-14 17:02:31 +08:00

37 lines
661 B
TypeScript

import { serve } from '@hono/node-server'
import { Hono } from 'hono'
const app = new Hono()
const accounts = {
'1': {amount: 1000},
'2': {amount: 1000},
}
const transactions = []
app.post('/transfer', async (c) => {
const body = await c.req.json();
const { amount, sender, receiver } = body;
if (amount <= 0) {
return c.json({ error: 'Amount must be greater than 0' }, 1000);
}
const transfer = {
amount,
sender,
receiver
}
console.log('transfer', transfe);
return c.json(transfer)
})
serve({
fetch: app.fetch,
port: 3000
}, (server) => {
console.log(`Server is running on http://localhost:${server.port}`)
})