24 lines
710 B
TypeScript
24 lines
710 B
TypeScript
import express, { Request, Response } from 'express';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
|
|
const router = express.Router()
|
|
|
|
const tileFolder = path.join(__dirname, '..', '..', '..', 'public', 'static')
|
|
|
|
router.get('/:city_id', async (req: Request, res: Response) => {
|
|
const { city_id } = req.params
|
|
|
|
const tilePath1 = path.join(tileFolder, `${city_id}.jpg`)
|
|
const tilePath2 = path.join(tileFolder, `${city_id}.png`)
|
|
|
|
if (fs.existsSync(tilePath1)) {
|
|
return res.sendFile(tilePath1)
|
|
} else if (fs.existsSync(tilePath2)) {
|
|
return res.sendFile(tilePath2)
|
|
} else {
|
|
res.status(404).send('Tile is not generated or not provided')
|
|
}
|
|
})
|
|
|
|
export default router |