Created
February 10, 2025 06:03
-
-
Save xanf/d838959216498cd67bbd3bbf11a5ee0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:22-slim | |
WORKDIR /app | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
RUN npm run build | |
EXPOSE 3000 | |
CMD ["npm", "start"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Hono } from "hono"; | |
import { serve } from "@hono/node-server"; | |
import type { FC } from "hono/jsx"; | |
const app = new Hono(); | |
const Layout: FC = (props) => { | |
return ( | |
<html> | |
<body>{props.children}</body> | |
</html> | |
); | |
}; | |
const InputForm = () => { | |
return ( | |
<Layout> | |
<h1>Hi! What is the secret word?</h1> | |
<form method="post" action="/submit"> | |
<input type="text" name="password" /> | |
<button type="submit">Submit</button> | |
</form> | |
</Layout> | |
); | |
}; | |
const Result: FC<{ message: string }> = (props) => { | |
return ( | |
<Layout> | |
<h1>{props.message}</h1> | |
<a href="/">Try again</a> | |
</Layout> | |
); | |
}; | |
const secret = Math.random().toString(36).substring(2, 8); | |
app.post("/submit", async (c) => { | |
const body = await c.req.formData(); | |
if (body.get("password") === secret) { | |
return c.html(<Result message="Correct!" />); | |
} | |
return c.html(<Result message="Incorrect!" />); | |
}); | |
app.get("/", (c) => { | |
const messages = ["Good Morning", "Good Evening", "Good Night"]; | |
return c.html(<InputForm />); | |
}); | |
serve(app); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "micropass", | |
"type": "module", | |
"scripts": { | |
"dev": "tsx watch index.tsx", | |
"build": "tsc", | |
"start": "node dist/index.js" | |
}, | |
"dependencies": { | |
"@hono/node-server": "^1.13.8", | |
"hono": "^4.6.20" | |
}, | |
"devDependencies": { | |
"@types/node": "^20.11.17", | |
"tsx": "^4.7.1", | |
"typescript": "^5.7.3" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "ESNext", | |
"module": "NodeNext", | |
"strict": true, | |
"verbatimModuleSyntax": true, | |
"skipLibCheck": true, | |
"types": ["node"], | |
"jsx": "react-jsx", | |
"jsxImportSource": "hono/jsx", | |
"outDir": "./dist" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment