This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
readyornot/pages/api/[map].tsx
2022-12-03 21:02:18 +01:00

16 lines
563 B
TypeScript

import fsPromises from 'fs/promises'
import path from 'path'
export default async function MapApi(req: any, res: any) {
const { map } = req.query
try {
// get Empire and Game name first to create an EmpireData object
const filePathMap = path.join(process.cwd(), '/public/images/'+map+'/info.json');
const jsonMapData = await fsPromises.readFile(filePathMap);
res.status(200).send(jsonMapData.toString())
}
catch (error) {
console.log(error)
res.status(500).json({error: 'Error reading data'})
}
}