You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
749 B
TypeScript
26 lines
749 B
TypeScript
import express from "express"
|
|
import path from "path"
|
|
import fs from "fs"
|
|
|
|
const image = express.Router();
|
|
|
|
image.get('/',
|
|
async (req: express.Request, res: express.Response): Promise<void> => {
|
|
let filename = req.query.filename as string;
|
|
|
|
try {
|
|
let filePath = path.resolve("images/full", `${filename}.jpg`);
|
|
console.log('FILE PATH', filePath);
|
|
if (!fs.existsSync(filePath)) {
|
|
res.status(404).send("Image don't exist! Try another name");
|
|
return;
|
|
}
|
|
res.sendFile(filePath);
|
|
} catch (err) {
|
|
res.status(404).send(`An error occured`);
|
|
}
|
|
|
|
//res.send('Welcome to image route please add parametres in the url');
|
|
})
|
|
|
|
export default image; |