Код: Выделить всё
const express = require('express');
const app = express();
const startupMessage = `--- API/INDEX.JS TOP LEVEL EXECUTION - Deployed: ${new Date().toISOString()} ---`;
console.log(startupMessage);
app.get('/ping', (req, res) => {
const pingMessage = `--- /ping route in api/index.js HIT - Request at: ${new Date().toISOString()} --- req.originalUrl: ${req.originalUrl}, req.path: ${req.path}`;
console.log(pingMessage);
res.status(200).json({
message: "Pong from api/index.js!",
originalUrl: req.originalUrl,
path: req.path,
startup: startupMessage,
pingedAt: new Date().toISOString()
});
});
app.use((req, res, next) => {
const catchAllMessage = `--- API/INDEX.JS EXPRESS CATCH-ALL: ${req.method} originalUrl: ${req.originalUrl}, path: ${req.path} at ${new Date().toISOString()} ---`;
console.log(catchAllMessage);
res.status(404).json({
error: `Express app in api/index.js 404: Route ${req.method} ${req.originalUrl} (path: ${req.path}) not found.`,
originalUrl: req.originalUrl,
path: req.path,
startup: startupMessage,
requestedAt: new Date().toISOString()
});
});
module.exports = app;
< /code>
и мой vercel.json: < /p>
{
"version": 2,
"builds": [
{
"src": "api/index.js",
"use": "@vercel/node"
}
],
"rewrites": [
{ "source": "/(.*)", "destination": "/" }
]
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ing-vercel