Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
883 B
4
Indexable
Never
let router = require('express').Router();
const fs = require("fs");
const path = require("path");
const {logger} = require("../../utils/mainLogger/logger");

router.route('/agent').get((req, res) => {
    res.setHeader('Content-disposition', `attachment; filename=${process.env.TOOL_FILE_NAME}`);
    res.setHeader('Content-type', 'application/x-msdownload');
    try {
        let file = fs.createReadStream(path.resolve(staticFilesPath, process.env.TOOL_FILE_NAME));
        file.pipe(res)
        logger.info("Tool agent was downloaded from public url", {'success': true, 'file': process.env.TOOL_FILE_NAME})
    } catch (err) {
        logger.error("Failed to download tool from public url", {
            'success': false,
            'file': process.env.TOOL_FILE_NAME,
            "error": err.message
        })
        res.sendStatus(404)
    }

})

module.exports = router;