|
1 | 1 | import express from 'express' |
| 2 | +import path from 'path' |
| 3 | +import { fileURLToPath } from 'url' |
| 4 | + |
| 5 | +const __filename = fileURLToPath(import.meta.url) |
| 6 | +const __dirname = path.dirname(__filename) |
2 | 7 |
|
3 | 8 | const app = express() |
4 | 9 |
|
5 | | -const runtime = typeof globalThis.Bun !== 'undefined' ? 'bun' : 'node' |
| 10 | +// Home route - HTML |
| 11 | +app.get('/', (req, res) => { |
| 12 | + res.type('html').send(` |
| 13 | + <!doctype html> |
| 14 | + <html> |
| 15 | + <head> |
| 16 | + <meta charset="utf-8"/> |
| 17 | + <title>Express + Bun ${process.versions.bun} on Vercel</title> |
| 18 | + <link rel="stylesheet" href="/style.css" /> |
| 19 | + </head> |
| 20 | + <body> |
| 21 | + <nav> |
| 22 | + <a href="/">Home</a> |
| 23 | + <a href="/about">About</a> |
| 24 | + <a href="/api-data">API Data</a> |
| 25 | + <a href="/healthz">Health</a> |
| 26 | + </nav> |
| 27 | + <h1>Welcome to Express + Bun ${process.versions.bun} on Vercel 🚀</h1> |
| 28 | + <p>This is a minimal example without a database or forms.</p> |
| 29 | + <img src="/logo.png" alt="Logo" width="120" /> |
| 30 | + </body> |
| 31 | + </html> |
| 32 | + `) |
| 33 | +}) |
6 | 34 |
|
7 | | -app.get('/', (_req, res) => { |
8 | | - res.send(`Hello from ${runtime}!`) |
| 35 | +app.get('/about', function (req, res) { |
| 36 | + res.sendFile(path.join(__dirname, '..', 'components', 'about.htm')) |
9 | 37 | }) |
10 | 38 |
|
11 | | -app.get('/api/users/:id', (_req, res) => { |
12 | | - res.json({ id: _req.params.id }) |
| 39 | +// Example API endpoint - JSON |
| 40 | +app.get('/api-data', (req, res) => { |
| 41 | + res.json({ |
| 42 | + message: 'Here is some sample API data', |
| 43 | + items: ['apple', 'banana', 'cherry'], |
| 44 | + }) |
13 | 45 | }) |
14 | 46 |
|
15 | | -app.get('/api/posts/:postId/comments/:commentId', (_req, res) => { |
16 | | - res.json({ postId: _req.params.postId, commentId: _req.params.commentId }) |
| 47 | +// Health check |
| 48 | +app.get('/healthz', (req, res) => { |
| 49 | + res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() }) |
17 | 50 | }) |
18 | 51 |
|
19 | 52 | export default app |
0 commit comments