Skip to content

Instantly share code, notes, and snippets.

@xanf
Created February 10, 2025 06:03
Show Gist options
  • Save xanf/d838959216498cd67bbd3bbf11a5ee0a to your computer and use it in GitHub Desktop.
Save xanf/d838959216498cd67bbd3bbf11a5ee0a to your computer and use it in GitHub Desktop.
FROM node:22-slim
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
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);
{
"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"
}
}
{
"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