UNPKG

@metacall/faas

Version:

Reimplementation of MetaCall FaaS platform written in TypeScript.

28 lines (27 loc) 1.42 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.serveStatic = void 0; const path_1 = __importDefault(require("path")); const app_1 = require("../app"); const appError_1 = __importDefault(require("../utils/appError")); const config_1 = require("../utils/config"); const filesystem_1 = require("../utils/filesystem"); const catch_1 = require("./catch"); exports.serveStatic = catch_1.catchAsync(async (req, res, next) => { if (!req.params) { throw new appError_1.default('Invalid API endpoint', 404); } const { suffix, file } = req.params; const application = app_1.Applications[suffix]; // Check if the application exists and it is running if (!(application === null || application === void 0 ? void 0 : application.proc)) { next(new appError_1.default(`Oops! It looks like the application 'suffix' hasn't been deployed yet. Please deploy it before you can call its functions.`, 404)); } const filePath = path_1.default.join(config_1.appsDirectory, suffix, file); if (!(await filesystem_1.exists(filePath))) next(new appError_1.default('The file you are looking for might not be available or the application may not be deployed.', 404)); return res.status(200).sendFile(filePath); });