@feardread/fear 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FEAR.js +1 -37
- package/libs/emailer/smtp.js +1 -1
- package/models/category.js +2 -55
- package/package.json +1 -1
package/FEAR.js
CHANGED
|
@@ -173,14 +173,11 @@ module.exports = FEAR = (() => {
|
|
|
173
173
|
|
|
174
174
|
mailinfo.service = mailService;
|
|
175
175
|
this.mailinfo = mailinfo;
|
|
176
|
-
|
|
177
176
|
if ( !this.mailer ) {
|
|
178
177
|
this.mailer = new smtp(this);
|
|
179
178
|
}
|
|
180
179
|
},
|
|
181
|
-
|
|
182
|
-
* Parse allowed origins from environment
|
|
183
|
-
*/
|
|
180
|
+
|
|
184
181
|
getAllowedOrigins() {
|
|
185
182
|
if (!this.env.ALLOWED_ORIGINS) return [];
|
|
186
183
|
|
|
@@ -190,9 +187,6 @@ module.exports = FEAR = (() => {
|
|
|
190
187
|
.filter(origin => origin.length > 0);
|
|
191
188
|
},
|
|
192
189
|
|
|
193
|
-
/**
|
|
194
|
-
* Get CORS configuration object
|
|
195
|
-
*/
|
|
196
190
|
getCorsConfig() {
|
|
197
191
|
return {
|
|
198
192
|
credentials: true,
|
|
@@ -209,9 +203,6 @@ module.exports = FEAR = (() => {
|
|
|
209
203
|
};
|
|
210
204
|
},
|
|
211
205
|
|
|
212
|
-
/**
|
|
213
|
-
* Auto-load routes from routes directory
|
|
214
|
-
*/
|
|
215
206
|
setupRoutes() {
|
|
216
207
|
const routesDir = path.join(__dirname, "routes");
|
|
217
208
|
|
|
@@ -241,9 +232,6 @@ module.exports = FEAR = (() => {
|
|
|
241
232
|
}
|
|
242
233
|
},
|
|
243
234
|
|
|
244
|
-
/**
|
|
245
|
-
* Register a single router
|
|
246
|
-
*/
|
|
247
235
|
useRouter(router, routePath = DEFAULT_ROUTE_PATH, corsOptions = null) {
|
|
248
236
|
if (!router || typeof router !== 'function') {
|
|
249
237
|
throw new Error('Router must be a valid Express router instance');
|
|
@@ -264,9 +252,6 @@ module.exports = FEAR = (() => {
|
|
|
264
252
|
return this;
|
|
265
253
|
},
|
|
266
254
|
|
|
267
|
-
/**
|
|
268
|
-
* Register multiple routers
|
|
269
|
-
*/
|
|
270
255
|
useRouters(routers) {
|
|
271
256
|
if (!Array.isArray(routers)) {
|
|
272
257
|
throw new Error('Routers must be an array');
|
|
@@ -285,9 +270,6 @@ module.exports = FEAR = (() => {
|
|
|
285
270
|
return this;
|
|
286
271
|
},
|
|
287
272
|
|
|
288
|
-
/**
|
|
289
|
-
* Create a new router with FEAR utilities attached
|
|
290
|
-
*/
|
|
291
273
|
createRouter() {
|
|
292
274
|
const router = express.Router();
|
|
293
275
|
|
|
@@ -305,9 +287,6 @@ module.exports = FEAR = (() => {
|
|
|
305
287
|
return router;
|
|
306
288
|
},
|
|
307
289
|
|
|
308
|
-
/**
|
|
309
|
-
* Get list of registered routers
|
|
310
|
-
*/
|
|
311
290
|
getRegisteredRouters() {
|
|
312
291
|
return this.registeredRouters.map(info => ({
|
|
313
292
|
path: info.path,
|
|
@@ -315,9 +294,6 @@ module.exports = FEAR = (() => {
|
|
|
315
294
|
}));
|
|
316
295
|
},
|
|
317
296
|
|
|
318
|
-
/**
|
|
319
|
-
* Start the HTTP server
|
|
320
|
-
*/
|
|
321
297
|
start(port = null) {
|
|
322
298
|
const serverPort = port || this.app.get("PORT") || DEFAULT_PORT;
|
|
323
299
|
|
|
@@ -340,9 +316,6 @@ module.exports = FEAR = (() => {
|
|
|
340
316
|
});
|
|
341
317
|
},
|
|
342
318
|
|
|
343
|
-
/**
|
|
344
|
-
* Gracefully shutdown the server
|
|
345
|
-
*/
|
|
346
319
|
shutdown() {
|
|
347
320
|
this.logger.info('Initiating graceful shutdown...');
|
|
348
321
|
|
|
@@ -382,9 +355,6 @@ module.exports = FEAR = (() => {
|
|
|
382
355
|
});
|
|
383
356
|
},
|
|
384
357
|
|
|
385
|
-
/**
|
|
386
|
-
* Close database connections
|
|
387
|
-
*/
|
|
388
358
|
closeDatabase() {
|
|
389
359
|
return new Promise((resolve, reject) => {
|
|
390
360
|
if (this.db && typeof this.db.disconnect === 'function') {
|
|
@@ -400,9 +370,6 @@ module.exports = FEAR = (() => {
|
|
|
400
370
|
});
|
|
401
371
|
},
|
|
402
372
|
|
|
403
|
-
/**
|
|
404
|
-
* Set FEAR utilities as global
|
|
405
|
-
*/
|
|
406
373
|
setAsGlobal() {
|
|
407
374
|
global.FearRouter = {
|
|
408
375
|
createRouter: () => this.createRouter(),
|
|
@@ -420,9 +387,6 @@ module.exports = FEAR = (() => {
|
|
|
420
387
|
return FEAR;
|
|
421
388
|
})();
|
|
422
389
|
|
|
423
|
-
/**
|
|
424
|
-
* Factory function to create new FEAR instance
|
|
425
|
-
*/
|
|
426
390
|
exports.FearFactory = () => {
|
|
427
391
|
return new FEAR();
|
|
428
392
|
};
|
package/libs/emailer/smtp.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = function (fear) {
|
|
|
24
24
|
throw new Error('Mailgun requires apiKey and domain in configuration.');
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const mailgun = new Mailgun(
|
|
27
|
+
const mailgun = new Mailgun(_this.mailConfig.mailgun);
|
|
28
28
|
const clientOptions = {
|
|
29
29
|
username: 'api',
|
|
30
30
|
key: apiKey
|
package/models/category.js
CHANGED
|
@@ -125,15 +125,13 @@ categorySchema.virtual("postCount", {
|
|
|
125
125
|
// Pre-save middleware
|
|
126
126
|
categorySchema.pre("save", async function(next) {
|
|
127
127
|
// Generate slug
|
|
128
|
-
if (this.isModified("
|
|
129
|
-
const nameToSlugify = this.title
|
|
128
|
+
if (this.isModified("title")) {
|
|
129
|
+
const nameToSlugify = this.title;
|
|
130
130
|
this.slug = slugify(nameToSlugify, {
|
|
131
131
|
lower: true,
|
|
132
132
|
strict: true,
|
|
133
133
|
remove: /[*+~.()'"!:@]/g
|
|
134
134
|
});
|
|
135
|
-
|
|
136
|
-
// Ensure unique slug
|
|
137
135
|
const slugRegEx = new RegExp(`^${this.slug}(-[0-9]*)?$`, "i");
|
|
138
136
|
const categoriesWithSlug = await this.constructor.find({
|
|
139
137
|
slug: slugRegEx,
|
|
@@ -145,22 +143,6 @@ categorySchema.pre("save", async function(next) {
|
|
|
145
143
|
}
|
|
146
144
|
}
|
|
147
145
|
|
|
148
|
-
// Sync name and title if one is missing
|
|
149
|
-
if (!this.name && this.title) {
|
|
150
|
-
this.name = this.title;
|
|
151
|
-
}
|
|
152
|
-
if (!this.title && this.name) {
|
|
153
|
-
this.title = this.name;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Sync isActive with active
|
|
157
|
-
if (this.isModified("isActive")) {
|
|
158
|
-
this.active = this.isActive;
|
|
159
|
-
}
|
|
160
|
-
if (this.isModified("active")) {
|
|
161
|
-
this.isActive = this.active;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
146
|
// Calculate level and build ancestors
|
|
165
147
|
if (this.isModified("parent")) {
|
|
166
148
|
if (this.parent) {
|
|
@@ -185,43 +167,8 @@ categorySchema.pre("save", async function(next) {
|
|
|
185
167
|
this.path = this.slug;
|
|
186
168
|
}
|
|
187
169
|
}
|
|
188
|
-
|
|
189
|
-
// Set SEO defaults
|
|
190
|
-
if (!this.seo.metaTitle) {
|
|
191
|
-
this.seo.metaTitle = (this.title || this.name).substring(0, 70);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (!this.seo.metaDescription && this.description) {
|
|
195
|
-
this.seo.metaDescription = this.description.substring(0, 160);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
next();
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Pre-update middleware
|
|
202
|
-
categorySchema.pre("findOneAndUpdate", async function(next) {
|
|
203
|
-
const update = this.getUpdate();
|
|
204
|
-
|
|
205
|
-
if (update.name || update.title) {
|
|
206
|
-
const nameToSlugify = update.title || update.name;
|
|
207
|
-
update.slug = slugify(nameToSlugify, {
|
|
208
|
-
lower: true,
|
|
209
|
-
strict: true,
|
|
210
|
-
remove: /[*+~.()'"!:@]/g
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (update.isActive !== undefined) {
|
|
215
|
-
update.active = update.isActive;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (update.active !== undefined) {
|
|
219
|
-
update.isActive = update.active;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
170
|
next();
|
|
223
171
|
});
|
|
224
|
-
|
|
225
172
|
// Post-remove middleware to clean up references
|
|
226
173
|
categorySchema.post("remove", async function(doc) {
|
|
227
174
|
// Remove from parent's children
|