diff --git a/api/discovery.js b/api/discovery.js index 8898828..2c55d5a 100644 --- a/api/discovery.js +++ b/api/discovery.js @@ -1,5 +1,5 @@ //discovery.js -export default function handler(req, res) { +const handler = async (req, res) => { if (req.method !== 'GET') { return res.status(405).json({ error: 'Method not allowed' }); } @@ -23,7 +23,7 @@ export default function handler(req, res) { required: false } ], - endpoint: `${baseUrl}/tools/greeting`, + endpoint: `/tools/greeting`, http_method: "POST" }, { @@ -37,16 +37,17 @@ export default function handler(req, res) { required: false } ], - endpoint: `${baseUrl}/tools/todays-date`, + endpoint: `/tools/todays-date`, http_method: "POST" }, { name: "rick-roll", description: "Rick rolls the user", parameters: [], - endpoint: `${baseUrl}/tools/rick-roll`, + endpoint: `/tools/rick-roll`, http_method: "POST" } ]; res.status(200).json({ functions }); } +module.exports = handler; diff --git a/api/hello.js b/api/hello.js new file mode 100644 index 0000000..b75573f --- /dev/null +++ b/api/hello.js @@ -0,0 +1,14 @@ +const handler = async (req, res) => { + try { + const { name = 'World' } = req.query; + res.status(200).json({ + message: `Hello, ${name}!`, + timestamp: new Date().toISOString(), + method: req.method + }); + } catch (error) { + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +module.exports = handler; diff --git a/api/test.js b/api/test.js deleted file mode 100644 index 2f48f32..0000000 --- a/api/test.js +++ /dev/null @@ -1,5 +0,0 @@ - -// api/test.js -export default function handler(req, res) { - res.status(200).json({ message: "Test endpoint working!" }); -} diff --git a/api/tools/greeting.js b/api/tools/greeting.js index ef316c6..9b1ded5 100644 --- a/api/tools/greeting.js +++ b/api/tools/greeting.js @@ -1,5 +1,5 @@ // api/tools/greeting.js -export default function handler(req, res) { +const handler = async (req, res) => { if (req.method !== 'POST') { return res.status(405).json({ error: 'Method not allowed' }); } @@ -30,3 +30,4 @@ export default function handler(req, res) { res.status(500).json({ error: 'Internal server error' }); } } +module.exports = handler; diff --git a/api/tools/rick-roll.js b/api/tools/rick-roll.js index 8814444..e2d01c3 100644 --- a/api/tools/rick-roll.js +++ b/api/tools/rick-roll.js @@ -1,5 +1,5 @@ // api/tools/rick-roll.js -export default function handler(req, res) { +const handler = async (req, res) => { if (req.method !== 'POST') { return res.status(405).json({ error: 'Method not allowed' }); } @@ -25,3 +25,4 @@ export default function handler(req, res) { res.status(500).json({ error: 'Internal server error' }); } } +module.exports = handler; diff --git a/api/tools/todays-date.js b/api/tools/todays-date.js index 9912436..09eca87 100644 --- a/api/tools/todays-date.js +++ b/api/tools/todays-date.js @@ -1,5 +1,5 @@ // api/tools/todays-date.js -export default function handler(req, res) { +const handler = async (req, res) => { if (req.method !== 'POST') { return res.status(405).json({ error: 'Method not allowed' }); } @@ -39,3 +39,4 @@ export default function handler(req, res) { res.status(500).json({ error: 'Internal server error' }); } } +module.exports = handler; diff --git a/package.json b/package.json deleted file mode 100644 index a42a5c0..0000000 --- a/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "opal-tools-registry", - "version": "1.0.0", - "description": "Simple Opal Tools Registry for Vercel", - "scripts": { - "dev": "dev", - "build": "build", - "deploy": "vercel --prod" - }, - "dependencies": {}, - "devDependencies": { - "vercel": "^32.0.0" - }, - "engines": { - "node": ">=16.0.0" - } -} diff --git a/vercel.json b/vercel.json index a308e33..4a76343 100644 --- a/vercel.json +++ b/vercel.json @@ -1,8 +1,31 @@ { - "$schema": "https://openapi.vercel.sh/vercel.json", + "version": 2, "builds": [ - { "src": "*.html", "use": "@vercel/static" }, - { "src": "*.py", "use": "@vercel/python" }, - { "src": "*.js", "use": "@vercel/node" } + { + "src": "api/**/*.js", + "use": "@vercel/node" + } + ], + "routes": [ + { + "src": "/api/([^/]+)", + "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], + "dest": "/api/$1.js" + }, + { + "src": "/api/([^/]+).*", + "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], + "dest": "/api/$1.js" + }, + { + "src": "/api/tools/([^/]+)", + "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], + "dest": "/api/tools/$1.js" + }, + { + "src": "/api/tools/([^/]+).*", + "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], + "dest": "/api/tools/$1.js" + } ] }