diff --git a/solutions/express/api/index.ts b/solutions/express/api/index.ts deleted file mode 100644 index 9f725d38f7..0000000000 --- a/solutions/express/api/index.ts +++ /dev/null @@ -1,55 +0,0 @@ -// api/index.js -const express = require('express'); -const path = require('path'); - -const app = express(); - -// Serve static files from /public -app.use(express.static(path.join(__dirname, '..', 'public'))); - -// Home route - HTML -app.get('/', (req, res) => { - res.type('html').send(` - - - - - Express on Vercel - - - - -

Welcome to Express on Vercel 🚀

-

This is a minimal example without a database or forms.

- Logo - - - `); -}); - -app.get('/about', function (req, res) { - res.sendFile(path.join(__dirname, '..', 'components', 'about.htm')); -}); - -// Example API endpoint - JSON -app.get('/api-data', (req, res) => { - res.json({ - message: 'Here is some sample API data', - items: ['apple', 'banana', 'cherry'] - }); -}); - -// Health check -app.get('/healthz', (req, res) => { - res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() }); -}); - -// Local dev listener (ignored on Vercel) -app.listen(3000, () => console.log('Server running on http://localhost:3000')); - -module.exports = app; diff --git a/solutions/express/package.json b/solutions/express/package.json index 59605b87af..3e48e5e3b7 100644 --- a/solutions/express/package.json +++ b/solutions/express/package.json @@ -2,15 +2,17 @@ "name": "express", "version": "1.0.0", "description": "", - "main": "index.ts", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "node api/index.ts" - }, + "type": "module", "keywords": [], "author": "", "license": "ISC", "dependencies": { - "express": "^4.18.2" + "@types/express": "^5.0.0", + "@vercel/postgres": "0.10.0", + "dotenv": "^16.4.0", + "express": "5.1.0" + }, + "devDependencies": { + "@types/node": "^22.0.0" } } diff --git a/solutions/express/public/logo.png b/solutions/express/public/images/logo.png similarity index 100% rename from solutions/express/public/logo.png rename to solutions/express/public/images/logo.png diff --git a/solutions/express/src/index.ts b/solutions/express/src/index.ts new file mode 100644 index 0000000000..36e6d8c1fb --- /dev/null +++ b/solutions/express/src/index.ts @@ -0,0 +1,59 @@ +import dotenv from 'dotenv'; +import express, { type Request, type Response } from 'express'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +dotenv.config(); + +const app = express(); + +const __filename = fileURLToPath(import.meta.url); +const rootDir = path.dirname(__filename); + +// Serve static files from the public directory +app.use(express.static(path.join(rootDir, '..', 'public'))); + +// Home route - HTML +app.get('/', (req, res) => { + res.type('html').send(` + + + + + Express on Vercel + + + + +

Welcome to Express on Vercel 🚀

+

This is a minimal example without a database or forms.

+ Logo + + + `); +}); + + +app.get('/about', function (req: Request, res: Response) { + res.sendFile(path.join(rootDir, '..', 'components', 'about.htm')); +}); + +// Example API endpoint - JSON +app.get('/api-data', (req, res) => { + res.json({ + message: 'Here is some sample API data', + items: ['apple', 'banana', 'cherry'] + }); +}); + +// Health check +app.get('/healthz', (req, res) => { + res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() }); +}); + +export default app; diff --git a/solutions/express/tsconfig.json b/solutions/express/tsconfig.json new file mode 100644 index 0000000000..4fc0685295 --- /dev/null +++ b/solutions/express/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "outDir": "./dist", + "rootDir": ".", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true + }, +} diff --git a/solutions/express/vercel.json b/solutions/express/vercel.json deleted file mode 100644 index ec61493355..0000000000 --- a/solutions/express/vercel.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "rewrites": [{ "source": "/(.*)", "destination": "/api" }] -}