@equinor/fusion-framework-cli
Version:
--- title: Fusion Framework CLI ---
47 lines • 2.42 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import parseJsonFromRequest from '../../utils/parse-json-request.js';
/**
* This plugin provides a simple way to manage application settings in a local development environment.
*
* This plugin will cache the settings in memory and respond to `PUT` requests to update the settings.
* Restarting the development server will reset the settings to the default values.
*
* @param options - The options for configuring the app settings plugin.
* @returns A Vite Plugin object that can be used to configure a server.
*
* The plugin provides the following functionality:
* - Matches requests based on a specified path pattern.
* - Handles `PUT` requests to update application settings.
* - Responds with the current application settings in JSON format.
*/
export function appSettingsPlugin(options) {
var _a, _b;
let appSettings = (_a = options.defaultSettings) !== null && _a !== void 0 ? _a : {};
const pathMatch = new RegExp((_b = options.match) !== null && _b !== void 0 ? _b : '/persons/me/apps/.*/settings');
return {
name: 'app-settings',
configureServer(server) {
server.middlewares.use((req, res, next) => __awaiter(this, void 0, void 0, function* () {
var _a;
if (!((_a = req.url) === null || _a === void 0 ? void 0 : _a.match(pathMatch))) {
return next();
}
if (req.method === 'PUT') {
appSettings = yield parseJsonFromRequest(req);
}
res.setHeader('content-type', 'application/json');
res.end(JSON.stringify(appSettings));
}));
},
};
}
export default appSettingsPlugin;
//# sourceMappingURL=index.js.map