25 lines
570 B
JavaScript
25 lines
570 B
JavaScript
const express = require('express');
|
|
const buildModel = require('./buildModel');
|
|
|
|
function initGlobals() {
|
|
if (this.config.globals) {
|
|
this.globals = {
|
|
Model: buildModel(this.config),
|
|
config: this.config.globals,
|
|
};
|
|
|
|
const router = express.Router();
|
|
|
|
this.config.globals.forEach((global) => {
|
|
router
|
|
.route(`/globals/${global.slug}`)
|
|
.get(this.requestHandlers.globals.findOne(global))
|
|
.post(this.requestHandlers.globals.update(global));
|
|
});
|
|
|
|
this.router.use(router);
|
|
}
|
|
}
|
|
|
|
module.exports = initGlobals;
|