axe-api 0.13.3 → 0.14.0
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/CHANGELOG.md +6 -0
- package/package.json +1 -2
- package/src/Server.js +0 -3
- package/src/resolvers/setExpressRoutes.js +15 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## [0.14.0 (2021-09-15)](https://github.com/axe-api/axe-api/compare/0.14.0...0.13.3)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- General hooks definition feature has been added. ([#81](https://github.com/axe-api/axe-api/issues/81))
|
|
8
|
+
|
|
3
9
|
## [0.13.3 (2021-09-15)](https://github.com/axe-api/axe-api/compare/0.13.2...0.13.3)
|
|
4
10
|
|
|
5
11
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "AXE API is a simple tool which has been created based on Express and Knex.js to create Rest APIs quickly.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"change-case": "^4.1.2",
|
|
23
|
-
"cors": "^2.8.5",
|
|
24
23
|
"dotenv": "^10.0.0",
|
|
25
24
|
"express": "^4.17.1",
|
|
26
25
|
"knex": "^0.95.8",
|
package/src/Server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import dotenv from "dotenv";
|
|
2
2
|
import express from "express";
|
|
3
3
|
import knex from "knex";
|
|
4
|
-
import cors from "cors";
|
|
5
4
|
import { attachPaginate } from "knex-paginate";
|
|
6
5
|
import Config from "./core/Config.js";
|
|
7
6
|
import IoC from "./core/IoC.js";
|
|
@@ -85,8 +84,6 @@ class Server {
|
|
|
85
84
|
async _listen() {
|
|
86
85
|
const Config = await IoC.use("Config");
|
|
87
86
|
|
|
88
|
-
this.app.use(cors(Config.Application.cors || {}));
|
|
89
|
-
|
|
90
87
|
this.app.get("/", (req, res) => {
|
|
91
88
|
res.json({
|
|
92
89
|
name: "AXE API",
|
|
@@ -237,7 +237,7 @@ const createRouteByModel = async (
|
|
|
237
237
|
await createNestedRoutes(model, models, allowRecursive, urlPrefix, resource);
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
-
const
|
|
240
|
+
const getGeneralHooks = async (appDirectory) => {
|
|
241
241
|
const fs = await IoC.use("fs");
|
|
242
242
|
const path = await IoC.use("path");
|
|
243
243
|
const url = await IoC.use("url");
|
|
@@ -245,11 +245,13 @@ const callAppInit = async (appDirectory, app) => {
|
|
|
245
245
|
// Calling the user's custom definitions
|
|
246
246
|
const customInitFile = path.join(appDirectory, `init.js`);
|
|
247
247
|
if (fs.existsSync(customInitFile)) {
|
|
248
|
-
const {
|
|
248
|
+
const { onBeforeInit, onAfterInit } = await import(
|
|
249
249
|
url.pathToFileURL(customInitFile).href
|
|
250
250
|
);
|
|
251
|
-
|
|
251
|
+
return { onBeforeInit, onAfterInit };
|
|
252
252
|
}
|
|
253
|
+
|
|
254
|
+
return { onBeforeInit: null, onAfterInit: null };
|
|
253
255
|
};
|
|
254
256
|
|
|
255
257
|
const createRoutesByModelTree = async (modelTree, models) => {
|
|
@@ -262,8 +264,17 @@ export default async (app, modelTree, appDirectory, models) => {
|
|
|
262
264
|
Config = await IoC.use("Config");
|
|
263
265
|
const logger = await IoC.use("Logger");
|
|
264
266
|
|
|
267
|
+
const { onBeforeInit, onAfterInit } = await getGeneralHooks(appDirectory);
|
|
268
|
+
|
|
269
|
+
if (typeof onBeforeInit === "function") {
|
|
270
|
+
await onBeforeInit({ app });
|
|
271
|
+
}
|
|
272
|
+
|
|
265
273
|
await createRoutesByModelTree(modelTree, models);
|
|
266
|
-
|
|
274
|
+
|
|
275
|
+
if (typeof onAfterInit === "function") {
|
|
276
|
+
await onAfterInit({ app });
|
|
277
|
+
}
|
|
267
278
|
|
|
268
279
|
logger.info("All routes have been created.");
|
|
269
280
|
};
|