@metacall/faas
Version:
Reimplementation of MetaCall FaaS platform written in TypeScript.
28 lines (27 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deployDelete = void 0;
const promises_1 = require("fs/promises");
const path_1 = require("path");
const app_1 = require("../app");
const config_1 = require("../utils/config");
const catch_1 = require("./catch");
exports.deployDelete = catch_1.catchAsync(async (req, res, _next) => {
// Extract the suffix (application name) of the application from the request body
const { suffix } = req.body;
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)) {
return res.send(`Oops! It looks like the application '${suffix}' hasn't been deployed yet. Please deploy it before you delete it.`);
}
// Retrieve the child process associated with the application and kill it
application.kill();
// Remove the application Applications object
delete app_1.Applications[suffix];
// Determine the location of the application
const appLocation = path_1.join(config_1.appsDirectory, suffix);
// Delete the directory of the application
await promises_1.rm(appLocation, { recursive: true, force: true });
// Send response based on whether there was an error during deletion
return res.send('Deploy delete succeed!');
});