@flink-app/flink 0.4.6 → 0.4.7
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/dist/src/FlinkApp.d.ts +6 -0
- package/dist/src/FlinkApp.js +33 -16
- package/package.json +2 -2
- package/src/FlinkApp.ts +37 -16
package/dist/src/FlinkApp.d.ts
CHANGED
|
@@ -107,6 +107,11 @@ export interface FlinkOptions {
|
|
|
107
107
|
*/
|
|
108
108
|
enabled?: boolean;
|
|
109
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* If true, the HTTP server will be disabled.
|
|
112
|
+
* Only useful when starting a Flink app for testing purposes.
|
|
113
|
+
*/
|
|
114
|
+
disableHttpServer?: boolean;
|
|
110
115
|
}
|
|
111
116
|
export interface HandlerConfig {
|
|
112
117
|
schema?: {
|
|
@@ -145,6 +150,7 @@ export declare class FlinkApp<C extends FlinkContext> {
|
|
|
145
150
|
private routingConfigured;
|
|
146
151
|
private jsonOptions?;
|
|
147
152
|
private schedulingOptions?;
|
|
153
|
+
private disableHttpServer;
|
|
148
154
|
private repos;
|
|
149
155
|
/**
|
|
150
156
|
* Internal cache used to track registered handlers and potentially any overlapping routes
|
package/dist/src/FlinkApp.js
CHANGED
|
@@ -93,6 +93,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
93
93
|
this.debug = false;
|
|
94
94
|
this.plugins = [];
|
|
95
95
|
this.routingConfigured = false;
|
|
96
|
+
this.disableHttpServer = false;
|
|
96
97
|
this.repos = {};
|
|
97
98
|
/**
|
|
98
99
|
* Internal cache used to track registered handlers and potentially any overlapping routes
|
|
@@ -108,6 +109,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
108
109
|
this.auth = opts.auth;
|
|
109
110
|
this.jsonOptions = opts.jsonOptions || { limit: "1mb" };
|
|
110
111
|
this.schedulingOptions = opts.scheduling;
|
|
112
|
+
this.disableHttpServer = !!opts.disableHttpServer;
|
|
111
113
|
}
|
|
112
114
|
Object.defineProperty(FlinkApp.prototype, "ctx", {
|
|
113
115
|
get: function () {
|
|
@@ -146,13 +148,18 @@ var FlinkApp = /** @class */ (function () {
|
|
|
146
148
|
if (this.isSchedulingEnabled) {
|
|
147
149
|
this.scheduler = new toad_scheduler_1.ToadScheduler();
|
|
148
150
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
else {
|
|
152
|
+
FlinkLog_1.log.info("🚫 Scheduling is disabled");
|
|
153
|
+
}
|
|
154
|
+
if (!this.disableHttpServer) {
|
|
155
|
+
this.expressApp = express_1.default();
|
|
156
|
+
this.expressApp.use(cors_1.default(this.corsOpts));
|
|
157
|
+
this.expressApp.use(body_parser_1.default.json(this.jsonOptions));
|
|
158
|
+
this.expressApp.use(function (req, res, next) {
|
|
159
|
+
req.reqId = uuid_1.v4();
|
|
160
|
+
next();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
156
163
|
_i = 0, _b = this.plugins;
|
|
157
164
|
_c.label = 3;
|
|
158
165
|
case 3:
|
|
@@ -196,15 +203,23 @@ var FlinkApp = /** @class */ (function () {
|
|
|
196
203
|
// Register 404 with slight delay to allow all manually added routes to be added
|
|
197
204
|
// TODO: Is there a better solution to force this handler to always run last?
|
|
198
205
|
setTimeout(function () {
|
|
199
|
-
_this.
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
if (!_this.disableHttpServer) {
|
|
207
|
+
_this.expressApp.use(function (req, res, next) {
|
|
208
|
+
res.status(404).json(FlinkErrors_1.notFound());
|
|
209
|
+
});
|
|
210
|
+
}
|
|
202
211
|
_this.routingConfigured = true;
|
|
203
212
|
});
|
|
204
|
-
|
|
205
|
-
FlinkLog_1.log.
|
|
206
|
-
|
|
207
|
-
}
|
|
213
|
+
if (this.disableHttpServer) {
|
|
214
|
+
FlinkLog_1.log.info("🚧 HTTP server is disabled, but flink app is running");
|
|
215
|
+
this.started = true;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
(_a = this.expressApp) === null || _a === void 0 ? void 0 : _a.listen(this.port, function () {
|
|
219
|
+
FlinkLog_1.log.fontColorLog("magenta", "\u26A1\uFE0F HTTP server '" + _this.name + "' is running and waiting for connections on " + _this.port);
|
|
220
|
+
_this.started = true;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
208
223
|
return [2 /*return*/, this];
|
|
209
224
|
}
|
|
210
225
|
});
|
|
@@ -258,13 +273,15 @@ var FlinkApp = /** @class */ (function () {
|
|
|
258
273
|
this.handlers.push(handlerConfig);
|
|
259
274
|
var routeProps = handlerConfig.routeProps, _a = handlerConfig.schema, schema = _a === void 0 ? {} : _a;
|
|
260
275
|
var method = routeProps.method;
|
|
261
|
-
var app = this.expressApp;
|
|
262
276
|
if (!method) {
|
|
263
277
|
FlinkLog_1.log.error("Route " + routeProps.path + " is missing http method");
|
|
264
278
|
}
|
|
265
279
|
if (method) {
|
|
266
280
|
var methodAndRoute_1 = method.toUpperCase() + " " + routeProps.path;
|
|
267
|
-
|
|
281
|
+
if (this.disableHttpServer) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.expressApp[method](routeProps.path, function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
268
285
|
var validate, valid, data, handlerRes, err_1, validate, valid;
|
|
269
286
|
return __generator(this, function (_a) {
|
|
270
287
|
switch (_a.label) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/flink",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Typescript only framework for creating REST-like APIs on top of Express and mongodb",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"rimraf": "^3.0.2",
|
|
66
66
|
"ts-node": "^9.1.1"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "b565d5987e08ba3aba3653325e935e6c56cab24c"
|
|
69
69
|
}
|
package/src/FlinkApp.ts
CHANGED
|
@@ -162,6 +162,12 @@ export interface FlinkOptions {
|
|
|
162
162
|
// */
|
|
163
163
|
// autoAssignCollection?: string;
|
|
164
164
|
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* If true, the HTTP server will be disabled.
|
|
168
|
+
* Only useful when starting a Flink app for testing purposes.
|
|
169
|
+
*/
|
|
170
|
+
disableHttpServer?: boolean;
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
export interface HandlerConfig {
|
|
@@ -203,6 +209,7 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
203
209
|
private routingConfigured = false;
|
|
204
210
|
private jsonOptions?: OptionsJson;
|
|
205
211
|
private schedulingOptions?: FlinkOptions["scheduling"];
|
|
212
|
+
private disableHttpServer = false;
|
|
206
213
|
|
|
207
214
|
private repos: { [x: string]: FlinkRepo<C> } = {};
|
|
208
215
|
|
|
@@ -224,6 +231,7 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
224
231
|
this.auth = opts.auth;
|
|
225
232
|
this.jsonOptions = opts.jsonOptions || { limit: "1mb" };
|
|
226
233
|
this.schedulingOptions = opts.scheduling;
|
|
234
|
+
this.disableHttpServer = !!opts.disableHttpServer;
|
|
227
235
|
}
|
|
228
236
|
|
|
229
237
|
get ctx() {
|
|
@@ -253,18 +261,22 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
253
261
|
|
|
254
262
|
if (this.isSchedulingEnabled) {
|
|
255
263
|
this.scheduler = new ToadScheduler();
|
|
264
|
+
} else {
|
|
265
|
+
log.info("🚫 Scheduling is disabled");
|
|
256
266
|
}
|
|
257
267
|
|
|
258
|
-
this.
|
|
268
|
+
if (!this.disableHttpServer) {
|
|
269
|
+
this.expressApp = express();
|
|
259
270
|
|
|
260
|
-
|
|
271
|
+
this.expressApp.use(cors(this.corsOpts));
|
|
261
272
|
|
|
262
|
-
|
|
273
|
+
this.expressApp.use(bodyParser.json(this.jsonOptions));
|
|
263
274
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
275
|
+
this.expressApp.use((req, res, next) => {
|
|
276
|
+
req.reqId = v4();
|
|
277
|
+
next();
|
|
278
|
+
});
|
|
279
|
+
}
|
|
268
280
|
|
|
269
281
|
// TODO: Add better more fine grained control when plugins are initialized, i.e. in what order
|
|
270
282
|
|
|
@@ -301,18 +313,24 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
301
313
|
// Register 404 with slight delay to allow all manually added routes to be added
|
|
302
314
|
// TODO: Is there a better solution to force this handler to always run last?
|
|
303
315
|
setTimeout(() => {
|
|
304
|
-
this.
|
|
305
|
-
|
|
306
|
-
|
|
316
|
+
if (!this.disableHttpServer) {
|
|
317
|
+
this.expressApp!.use((req, res, next) => {
|
|
318
|
+
res.status(404).json(notFound());
|
|
319
|
+
});
|
|
320
|
+
}
|
|
307
321
|
|
|
308
322
|
this.routingConfigured = true;
|
|
309
323
|
});
|
|
310
324
|
|
|
311
|
-
|
|
312
|
-
log.
|
|
313
|
-
|
|
325
|
+
if (this.disableHttpServer) {
|
|
326
|
+
log.info("🚧 HTTP server is disabled, but flink app is running");
|
|
314
327
|
this.started = true;
|
|
315
|
-
}
|
|
328
|
+
} else {
|
|
329
|
+
this.expressApp?.listen(this.port, () => {
|
|
330
|
+
log.fontColorLog("magenta", `⚡️ HTTP server '${this.name}' is running and waiting for connections on ${this.port}`);
|
|
331
|
+
this.started = true;
|
|
332
|
+
});
|
|
333
|
+
}
|
|
316
334
|
|
|
317
335
|
return this;
|
|
318
336
|
}
|
|
@@ -381,7 +399,6 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
381
399
|
|
|
382
400
|
const { routeProps, schema = {} } = handlerConfig;
|
|
383
401
|
const { method } = routeProps;
|
|
384
|
-
const app = this.expressApp!;
|
|
385
402
|
|
|
386
403
|
if (!method) {
|
|
387
404
|
log.error(`Route ${routeProps.path} is missing http method`);
|
|
@@ -390,7 +407,11 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
390
407
|
if (method) {
|
|
391
408
|
const methodAndRoute = `${method.toUpperCase()} ${routeProps.path}`;
|
|
392
409
|
|
|
393
|
-
|
|
410
|
+
if (this.disableHttpServer) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
this.expressApp => {
|
|
394
415
|
if (routeProps.permissions) {
|
|
395
416
|
if (!(await this.authenticate(req, routeProps.permissions))) {
|
|
396
417
|
return res.status(401).json(unauthorized());
|