@flink-app/flink 0.11.4 → 0.11.5
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 +5 -0
- package/dist/src/FlinkApp.js +25 -18
- package/package.json +2 -2
- package/src/FlinkApp.ts +14 -0
package/dist/src/FlinkApp.d.ts
CHANGED
|
@@ -100,6 +100,10 @@ export interface FlinkOptions {
|
|
|
100
100
|
* Options for json body parser
|
|
101
101
|
*/
|
|
102
102
|
jsonOptions?: OptionsJson;
|
|
103
|
+
/**
|
|
104
|
+
* Optional: content-types that should be parsed as raw body, and passed as a Buffer object instead of json
|
|
105
|
+
*/
|
|
106
|
+
rawContentTypes?: string | string[];
|
|
103
107
|
scheduling?: {
|
|
104
108
|
/**
|
|
105
109
|
* If true, the scheduler will be enabled.
|
|
@@ -164,6 +168,7 @@ export declare class FlinkApp<C extends FlinkContext> {
|
|
|
164
168
|
private corsOpts;
|
|
165
169
|
private routingConfigured;
|
|
166
170
|
private jsonOptions?;
|
|
171
|
+
private rawContentTypes?;
|
|
167
172
|
private schedulingOptions?;
|
|
168
173
|
private disableHttpServer;
|
|
169
174
|
private repos;
|
package/dist/src/FlinkApp.js
CHANGED
|
@@ -107,6 +107,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
107
107
|
this.onDbConnection = opts.onDbConnection;
|
|
108
108
|
this.plugins = opts.plugins || [];
|
|
109
109
|
this.corsOpts = __assign(__assign({}, defaultCorsOptions), opts.cors);
|
|
110
|
+
this.rawContentTypes = Array.isArray(opts.rawContentTypes) ? opts.rawContentTypes : (typeof opts.rawContentTypes === 'string' ? [opts.rawContentTypes] : undefined);
|
|
110
111
|
this.auth = opts.auth;
|
|
111
112
|
this.jsonOptions = opts.jsonOptions || { limit: "1mb" };
|
|
112
113
|
this.schedulingOptions = opts.scheduling;
|
|
@@ -126,23 +127,23 @@ var FlinkApp = /** @class */ (function () {
|
|
|
126
127
|
FlinkApp.prototype.start = function () {
|
|
127
128
|
var _a;
|
|
128
129
|
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
-
var startTime, offsetTime, _i, _b, plugin, db;
|
|
130
|
+
var startTime, offsetTime, _i, _b, type, _c, _d, plugin, db;
|
|
130
131
|
var _this = this;
|
|
131
|
-
return __generator(this, function (
|
|
132
|
-
switch (
|
|
132
|
+
return __generator(this, function (_e) {
|
|
133
|
+
switch (_e.label) {
|
|
133
134
|
case 0:
|
|
134
135
|
startTime = Date.now();
|
|
135
136
|
offsetTime = 0;
|
|
136
137
|
return [4 /*yield*/, this.initDb()];
|
|
137
138
|
case 1:
|
|
138
|
-
|
|
139
|
+
_e.sent();
|
|
139
140
|
if (this.debug) {
|
|
140
141
|
offsetTime = Date.now();
|
|
141
142
|
FlinkLog_1.log.bgColorLog("cyan", "Init db took " + (offsetTime - startTime) + " ms");
|
|
142
143
|
}
|
|
143
144
|
return [4 /*yield*/, this.buildContext()];
|
|
144
145
|
case 2:
|
|
145
|
-
|
|
146
|
+
_e.sent();
|
|
146
147
|
if (this.debug) {
|
|
147
148
|
FlinkLog_1.log.bgColorLog("cyan", "Build context took " + (Date.now() - offsetTime) + " ms");
|
|
148
149
|
offsetTime = Date.now();
|
|
@@ -156,6 +157,12 @@ var FlinkApp = /** @class */ (function () {
|
|
|
156
157
|
if (!this.disableHttpServer) {
|
|
157
158
|
this.expressApp = express_1.default();
|
|
158
159
|
this.expressApp.use(cors_1.default(this.corsOpts));
|
|
160
|
+
if (this.rawContentTypes) {
|
|
161
|
+
for (_i = 0, _b = this.rawContentTypes; _i < _b.length; _i++) {
|
|
162
|
+
type = _b[_i];
|
|
163
|
+
this.expressApp.use(express_1.default.raw({ type: type }));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
159
166
|
this.expressApp.use(body_parser_1.default.json(this.jsonOptions));
|
|
160
167
|
if (this.accessLog.enabled) {
|
|
161
168
|
this.expressApp.use(morgan_1.default(this.accessLog.format));
|
|
@@ -165,32 +172,32 @@ var FlinkApp = /** @class */ (function () {
|
|
|
165
172
|
next();
|
|
166
173
|
});
|
|
167
174
|
}
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
_c = 0, _d = this.plugins;
|
|
176
|
+
_e.label = 3;
|
|
170
177
|
case 3:
|
|
171
|
-
if (!(
|
|
172
|
-
plugin =
|
|
178
|
+
if (!(_c < _d.length)) return [3 /*break*/, 9];
|
|
179
|
+
plugin = _d[_c];
|
|
173
180
|
db = void 0;
|
|
174
181
|
if (!plugin.db) return [3 /*break*/, 5];
|
|
175
182
|
return [4 /*yield*/, this.initPluginDb(plugin)];
|
|
176
183
|
case 4:
|
|
177
|
-
db =
|
|
178
|
-
|
|
184
|
+
db = _e.sent();
|
|
185
|
+
_e.label = 5;
|
|
179
186
|
case 5:
|
|
180
187
|
if (!plugin.init) return [3 /*break*/, 7];
|
|
181
188
|
return [4 /*yield*/, plugin.init(this, db)];
|
|
182
189
|
case 6:
|
|
183
|
-
|
|
184
|
-
|
|
190
|
+
_e.sent();
|
|
191
|
+
_e.label = 7;
|
|
185
192
|
case 7:
|
|
186
193
|
FlinkLog_1.log.info("Initialized plugin '" + plugin.id + "'");
|
|
187
|
-
|
|
194
|
+
_e.label = 8;
|
|
188
195
|
case 8:
|
|
189
|
-
|
|
196
|
+
_c++;
|
|
190
197
|
return [3 /*break*/, 3];
|
|
191
198
|
case 9: return [4 /*yield*/, this.registerAutoRegisterableHandlers()];
|
|
192
199
|
case 10:
|
|
193
|
-
|
|
200
|
+
_e.sent();
|
|
194
201
|
if (this.debug) {
|
|
195
202
|
FlinkLog_1.log.bgColorLog("cyan", "Register handlers took " + (Date.now() - offsetTime) + " ms");
|
|
196
203
|
offsetTime = Date.now();
|
|
@@ -198,12 +205,12 @@ var FlinkApp = /** @class */ (function () {
|
|
|
198
205
|
if (!this.isSchedulingEnabled) return [3 /*break*/, 12];
|
|
199
206
|
return [4 /*yield*/, this.registerAutoRegisterableJobs()];
|
|
200
207
|
case 11:
|
|
201
|
-
|
|
208
|
+
_e.sent();
|
|
202
209
|
if (this.debug) {
|
|
203
210
|
FlinkLog_1.log.bgColorLog("cyan", "Register jobs took " + (Date.now() - offsetTime) + " ms");
|
|
204
211
|
offsetTime = Date.now();
|
|
205
212
|
}
|
|
206
|
-
|
|
213
|
+
_e.label = 12;
|
|
207
214
|
case 12:
|
|
208
215
|
// Register 404 with slight delay to allow all manually added routes to be added
|
|
209
216
|
// TODO: Is there a better solution to force this handler to always run last?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/flink",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
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",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"rimraf": "^3.0.2",
|
|
68
68
|
"ts-node": "^9.1.1"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "3e4488748859fc5f1de798dea4ea2611f9694221"
|
|
71
71
|
}
|
package/src/FlinkApp.ts
CHANGED
|
@@ -138,6 +138,11 @@ export interface FlinkOptions {
|
|
|
138
138
|
*/
|
|
139
139
|
jsonOptions?: OptionsJson;
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Optional: content-types that should be parsed as raw body, and passed as a Buffer object instead of json
|
|
143
|
+
*/
|
|
144
|
+
rawContentTypes?: string | string[];
|
|
145
|
+
|
|
141
146
|
scheduling?: {
|
|
142
147
|
/**
|
|
143
148
|
* If true, the scheduler will be enabled.
|
|
@@ -226,6 +231,7 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
226
231
|
private corsOpts: FlinkOptions["cors"];
|
|
227
232
|
private routingConfigured = false;
|
|
228
233
|
private jsonOptions?: OptionsJson;
|
|
234
|
+
private rawContentTypes?: string[];
|
|
229
235
|
private schedulingOptions?: FlinkOptions["scheduling"];
|
|
230
236
|
private disableHttpServer = false;
|
|
231
237
|
|
|
@@ -248,6 +254,7 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
248
254
|
this.onDbConnection = opts.onDbConnection;
|
|
249
255
|
this.plugins = opts.plugins || [];
|
|
250
256
|
this.corsOpts = { ...defaultCorsOptions, ...opts.cors };
|
|
257
|
+
this.rawContentTypes = Array.isArray(opts.rawContentTypes) ? opts.rawContentTypes : (typeof opts.rawContentTypes === 'string' ? [opts.rawContentTypes] : undefined);
|
|
251
258
|
this.auth = opts.auth;
|
|
252
259
|
this.jsonOptions = opts.jsonOptions || { limit: "1mb" };
|
|
253
260
|
this.schedulingOptions = opts.scheduling;
|
|
@@ -289,6 +296,13 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
289
296
|
if (!this.disableHttpServer) {
|
|
290
297
|
this.expressApp = express();
|
|
291
298
|
this.expressApp.use(cors(this.corsOpts));
|
|
299
|
+
|
|
300
|
+
if (this.rawContentTypes) {
|
|
301
|
+
for (const type of this.rawContentTypes) {
|
|
302
|
+
this.expressApp.use(express.raw({ type }));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
292
306
|
this.expressApp.use(bodyParser.json(this.jsonOptions));
|
|
293
307
|
|
|
294
308
|
if (this.accessLog.enabled) {
|