UNPKG

respond-framework

Version:
37 lines (35 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _db = require("../modules/replayTools/db.js"); var _createApiHandler = require("../createModule/createApiHandler.js"); var _utils = require("../utils.js"); const createApi = opts => { const options = createOptions(opts); const apiHandler = (0, _createApiHandler.default)(options); return async (req, res) => { try { await apiHandler(req, res); // this function is used directly in development on the client as well } catch (error) { console.error('respond: the following error occurred in a table method', req.body, error); res.json({ error: 'unknown-server-error', params: { ...req.body, message: error.message } }); } }; }; var _default = exports.default = createApi; const createOptions = (opts = {}) => { if (!_utils.isDev) return opts; opts.context ??= {}; // eg opts.context.io can be assigned to socket.io in userland opts.db ??= {}; opts.db.moduleKeys.push('replayTools'); opts.db.replayTools = _db.default; return opts; };