Hi @hedkace, I was able to get your app working (try here) with the following changes:
- move the
index.jsinapi/index.jsfile - remove legacy options from the
vercel.json - update
index.jsto correctly handle file paths
import express from "express";
import { parseFile } from "tmx-parser";
import { join } from "path";
// Create Express app
const app = express();
app.use(express.json());
// Helper function to parse TMX file using promises
async function parseTmxFile(filePath) {
return new Promise((resolve, reject) => {
parseFile(filePath, (err, loadedMap) => {
if (err) return reject(err);
resolve(loadedMap);
});
});
}
async function loadMap() {
try {
// Use a path relative to the function's directory
const filePath = join(__dirname, "..", "snowmap1.tmx");
mapCache = await parseTmxFile(filePath);
return mapCache;
} catch (error) {
console.error("Error loading map:", error);
throw error;
}
}
// Define routes
app.get("/test", (req, res) => {
res.json({ message: "test ok" });
});
app.get("/", async (req, res) => {
try {
const map = await loadMap();
console.log({ map });
res.json({
data: { version: map.version, width: map.width, height: map.height },
});
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
});
app.listen(3000, () => console.log("Server ready on port 3000."));
module.exports = app;
{
"rewrites": [{ "source": "/(.*)", "destination": "/api/index" }]
}