@a11ywatch/core
Version:
a11ywatch central API
27 lines • 1.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getServerConfig = void 0;
const config_1 = require("./config");
const utils_1 = require("./core/utils");
const schema_1 = require("./core/schema");
const strings_1 = require("./core/strings");
const getServerConfig = (extra) => {
const schema = (0, schema_1.createScheme)();
return Object.assign(Object.assign({}, extra), { introspection: config_1.SUPER_MODE, schema, cache: "bounded", csrfPrevention: true, context: (ctx) => {
var _a;
const req = ctx === null || ctx === void 0 ? void 0 : ctx.request;
const authentication = ((_a = req === null || req === void 0 ? void 0 : req.headers) === null || _a === void 0 ? void 0 : _a.authorization) || "";
const body = req === null || req === void 0 ? void 0 : req.body;
const user = (0, utils_1.getUserFromToken)(authentication);
const operation = body ? body === null || body === void 0 ? void 0 : body.operationName : "";
if (!user && operation && !config_1.BYPASS_AUTH.includes(operation)) {
throw new Error(strings_1.AUTH_ERROR);
}
return {
user,
res: ctx.reply,
};
} });
};
exports.getServerConfig = getServerConfig;
//# sourceMappingURL=apollo-server.js.map
;