@proteinjs/server 1.6.1 → 1.7.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/CHANGELOG.md +11 -0
- package/dist/generated/index.d.ts +1 -1
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +2 -2
- package/dist/generated/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/Request.d.ts +13 -0
- package/dist/src/Request.d.ts.map +1 -0
- package/dist/src/Request.js +47 -0
- package/dist/src/Request.js.map +1 -0
- package/dist/src/loadRoutes.d.ts.map +1 -1
- package/dist/src/loadRoutes.js +145 -103
- package/dist/src/loadRoutes.js.map +1 -1
- package/dist/src/startServer.js +52 -44
- package/dist/src/startServer.js.map +1 -1
- package/generated/index.ts +2 -2
- package/index.ts +1 -0
- package/package.json +7 -7
- package/src/Request.ts +50 -0
- package/src/loadRoutes.ts +80 -49
- package/src/startServer.ts +39 -45
package/dist/src/startServer.js
CHANGED
|
@@ -53,10 +53,10 @@ var http_1 = require("http");
|
|
|
53
53
|
var socket_io_1 = require("socket.io");
|
|
54
54
|
var server_api_1 = require("@proteinjs/server-api");
|
|
55
55
|
var loadRoutes_1 = require("./loadRoutes");
|
|
56
|
-
var
|
|
56
|
+
var logger_1 = require("@proteinjs/logger");
|
|
57
57
|
var nodeModulesPath_1 = require("./nodeModulesPath");
|
|
58
58
|
var staticContentPath = '/static/';
|
|
59
|
-
var logger = new
|
|
59
|
+
var logger = new logger_1.Logger({ name: 'Server' });
|
|
60
60
|
var app = (0, express_1.default)();
|
|
61
61
|
var server = new http_1.Server(app);
|
|
62
62
|
exports.io = new socket_io_1.Server(server);
|
|
@@ -71,11 +71,11 @@ function startServer(config) {
|
|
|
71
71
|
routes = (0, server_api_1.getRoutes)();
|
|
72
72
|
configureRequests(app);
|
|
73
73
|
initializeHotReloading(app, config);
|
|
74
|
+
configureSession(app, config);
|
|
74
75
|
beforeRequest(app, config);
|
|
75
76
|
(0, loadRoutes_1.loadRoutes)(routes.filter(function (route) { return route.useHttp; }), app, config);
|
|
76
77
|
configureHttps(app); // registering here forces static content to be redirected to https
|
|
77
|
-
configureStaticContentRouter(app, config);
|
|
78
|
-
configureSession(app, config);
|
|
78
|
+
configureStaticContentRouter(app, config);
|
|
79
79
|
(0, loadRoutes_1.loadRoutes)(routes.filter(function (route) { return !route.useHttp; }), app, config);
|
|
80
80
|
globalData = {};
|
|
81
81
|
_i = 0, _a = (0, server_api_1.getGlobalDataCaches)();
|
|
@@ -101,11 +101,11 @@ function startServer(config) {
|
|
|
101
101
|
case 6:
|
|
102
102
|
_d.sent();
|
|
103
103
|
if (!config.onStartup) return [3 /*break*/, 8];
|
|
104
|
-
logger.info("Starting ServerConfig.onStartup");
|
|
104
|
+
logger.info({ message: "Starting ServerConfig.onStartup" });
|
|
105
105
|
return [4 /*yield*/, config.onStartup()];
|
|
106
106
|
case 7:
|
|
107
107
|
_d.sent();
|
|
108
|
-
logger.info("Finished ServerConfig.onStartup");
|
|
108
|
+
logger.info({ message: "Finished ServerConfig.onStartup" });
|
|
109
109
|
_d.label = 8;
|
|
110
110
|
case 8:
|
|
111
111
|
start(server, config);
|
|
@@ -129,23 +129,27 @@ function runStartupTasks(when) {
|
|
|
129
129
|
if (filteredTasks.length === 0) {
|
|
130
130
|
return [2 /*return*/];
|
|
131
131
|
}
|
|
132
|
-
logger.info(
|
|
132
|
+
logger.info({
|
|
133
|
+
message: "Starting ".concat(filteredTasks.length, " `").concat(when, "` startup task").concat(filteredTasks.length > 1 ? 's' : ''),
|
|
134
|
+
});
|
|
133
135
|
return [4 /*yield*/, Promise.all(filteredTasks.map(function (task) { return __awaiter(_this, void 0, void 0, function () {
|
|
134
136
|
return __generator(this, function (_a) {
|
|
135
137
|
switch (_a.label) {
|
|
136
138
|
case 0:
|
|
137
|
-
logger.info("Starting task: ".concat(task.name));
|
|
139
|
+
logger.info({ message: "Starting task: ".concat(task.name) });
|
|
138
140
|
return [4 /*yield*/, task.run()];
|
|
139
141
|
case 1:
|
|
140
142
|
_a.sent();
|
|
141
|
-
logger.info("Finished task: ".concat(task.name));
|
|
143
|
+
logger.info({ message: "Finished task: ".concat(task.name) });
|
|
142
144
|
return [2 /*return*/];
|
|
143
145
|
}
|
|
144
146
|
});
|
|
145
147
|
}); }))];
|
|
146
148
|
case 1:
|
|
147
149
|
_a.sent();
|
|
148
|
-
logger.info(
|
|
150
|
+
logger.info({
|
|
151
|
+
message: "Finished ".concat(filteredTasks.length, " `").concat(when, "` startup task").concat(filteredTasks.length > 1 ? 's' : ''),
|
|
152
|
+
});
|
|
149
153
|
return [2 /*return*/];
|
|
150
154
|
}
|
|
151
155
|
});
|
|
@@ -191,7 +195,7 @@ function configureHttps(app) {
|
|
|
191
195
|
next();
|
|
192
196
|
return;
|
|
193
197
|
}
|
|
194
|
-
logger.debug("Redirecting to https: ".concat(request.headers.host + request.url));
|
|
198
|
+
logger.debug({ message: "Redirecting to https: ".concat(request.headers.host + request.url) });
|
|
195
199
|
response.redirect('https://' + request.headers.host + request.url);
|
|
196
200
|
});
|
|
197
201
|
}
|
|
@@ -201,7 +205,9 @@ function configureStaticContentRouter(app, config) {
|
|
|
201
205
|
return;
|
|
202
206
|
}
|
|
203
207
|
app.use(staticContentPath, express_1.default.static(config.staticContent.staticContentDir));
|
|
204
|
-
logger.info(
|
|
208
|
+
logger.info({
|
|
209
|
+
message: "Serving static content on path: ".concat(staticContentPath, ", serving from directory: ").concat(config.staticContent.staticContentDir),
|
|
210
|
+
});
|
|
205
211
|
}
|
|
206
212
|
function configureSession(app, config) {
|
|
207
213
|
var sixtyDays = 1000 * 60 * 60 * 24 * 60;
|
|
@@ -241,7 +247,7 @@ function initializeAuthentication(authenticate) {
|
|
|
241
247
|
return __generator(this, function (_a) {
|
|
242
248
|
switch (_a.label) {
|
|
243
249
|
case 0:
|
|
244
|
-
logger.info("Authenticating");
|
|
250
|
+
logger.info({ message: "Authenticating" });
|
|
245
251
|
return [4 /*yield*/, authenticate(username, password)];
|
|
246
252
|
case 1:
|
|
247
253
|
result = _a.sent();
|
|
@@ -261,42 +267,44 @@ function initializeAuthentication(authenticate) {
|
|
|
261
267
|
});
|
|
262
268
|
}
|
|
263
269
|
function beforeRequest(app, config) {
|
|
270
|
+
var _this = this;
|
|
264
271
|
var _a, _b, _c;
|
|
265
|
-
var requestCounter = 0;
|
|
266
272
|
if (((_a = config.request) === null || _a === void 0 ? void 0 : _a.disableRequestLogging) == false || typeof ((_b = config.request) === null || _b === void 0 ? void 0 : _b.disableRequestLogging) === 'undefined') {
|
|
267
|
-
app.use(function (request, response, next) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
273
|
+
app.use(function (request, response, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
274
|
+
return __generator(this, function (_a) {
|
|
275
|
+
switch (_a.label) {
|
|
276
|
+
case 0:
|
|
277
|
+
if (!config.authenticate) return [3 /*break*/, 2];
|
|
278
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
279
|
+
passport_1.default.authenticate('local', function (err, user, info) {
|
|
280
|
+
if (err) {
|
|
281
|
+
reject(err);
|
|
282
|
+
}
|
|
283
|
+
resolve();
|
|
284
|
+
})(request, response, next);
|
|
285
|
+
})];
|
|
286
|
+
case 1:
|
|
287
|
+
_a.sent();
|
|
288
|
+
_a.label = 2;
|
|
289
|
+
case 2:
|
|
290
|
+
next();
|
|
291
|
+
return [2 /*return*/];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}); });
|
|
277
295
|
}
|
|
278
296
|
if ((_c = config.request) === null || _c === void 0 ? void 0 : _c.beforeRequest) {
|
|
279
297
|
app.use(config.request.beforeRequest);
|
|
280
298
|
}
|
|
281
299
|
}
|
|
282
300
|
function afterRequest(app, config) {
|
|
283
|
-
var _a
|
|
301
|
+
var _a;
|
|
284
302
|
if ((_a = config.request) === null || _a === void 0 ? void 0 : _a.afterRequest) {
|
|
285
303
|
app.use(config.request.afterRequest);
|
|
286
304
|
}
|
|
287
|
-
if (((_b = config.request) === null || _b === void 0 ? void 0 : _b.disableRequestLogging) == false || typeof ((_c = config.request) === null || _c === void 0 ? void 0 : _c.disableRequestLogging) === 'undefined') {
|
|
288
|
-
app.use(function (request, response, next) {
|
|
289
|
-
if (request.path.startsWith('/static') || request.path.startsWith('/favicon.ico')) {
|
|
290
|
-
next();
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
logger.info("[#".concat(response.locals.requestNumber, "] Finished ").concat(request.originalUrl));
|
|
294
|
-
next();
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
305
|
}
|
|
298
306
|
function initializeSocketIO(io, app) {
|
|
299
|
-
var
|
|
307
|
+
var socketLogger = new logger_1.Logger({ name: 'SocketIOServer' });
|
|
300
308
|
// Share session and passport middleware with Socket.IO
|
|
301
309
|
var wrapMiddleware = function (middleware) { return function (socket, next) { return middleware(socket.request, {}, next); }; };
|
|
302
310
|
var sessionMiddleware = app.get('sessionMiddleware');
|
|
@@ -315,34 +323,34 @@ function initializeSocketIO(io, app) {
|
|
|
315
323
|
// Initialize Socket.IO event handlers
|
|
316
324
|
io.on('connection', function (socket) {
|
|
317
325
|
var userInfo = "".concat(socket.request.user, " (").concat(socket.id, ")");
|
|
318
|
-
|
|
326
|
+
socketLogger.info({ message: "User connected: ".concat(userInfo) });
|
|
319
327
|
// Map this socket to the session id so it can be closed when the session is destroyed
|
|
320
328
|
var sessionId = socket.request.sessionID;
|
|
321
329
|
if (sessionId) {
|
|
322
330
|
socket.join(sessionId);
|
|
323
331
|
}
|
|
324
332
|
socket.on('disconnect', function (reason) {
|
|
325
|
-
|
|
333
|
+
socketLogger.info({ message: "User disconnected: ".concat(userInfo, ". Reason: ").concat(reason) });
|
|
326
334
|
});
|
|
327
335
|
socket.on('error', function (error) {
|
|
328
|
-
|
|
336
|
+
socketLogger.error({ message: "Socket error for user: ".concat(userInfo), error: error });
|
|
329
337
|
});
|
|
330
338
|
socket.conn.on('error', function (error) {
|
|
331
|
-
|
|
339
|
+
socketLogger.error({ message: "Socket connection error for user: ".concat(userInfo), error: error });
|
|
332
340
|
});
|
|
333
341
|
});
|
|
334
342
|
// Handle server-level errors
|
|
335
|
-
io.engine.on('connection_error', function (
|
|
336
|
-
|
|
343
|
+
io.engine.on('connection_error', function (error) {
|
|
344
|
+
socketLogger.error({ message: 'Connection error', error: error });
|
|
337
345
|
});
|
|
338
346
|
}
|
|
339
347
|
function start(server, config) {
|
|
340
348
|
var port = config.port ? config.port : 3000;
|
|
341
349
|
server.listen(port, function () {
|
|
342
350
|
if (process.env.DEVELOPMENT) {
|
|
343
|
-
logger.info("Starting in development mode");
|
|
351
|
+
logger.info({ message: "Starting in development mode" });
|
|
344
352
|
}
|
|
345
|
-
logger.info("Server listening on port: ".concat(port));
|
|
353
|
+
logger.info({ message: "Server listening on port: ".concat(port) });
|
|
346
354
|
});
|
|
347
355
|
}
|
|
348
356
|
//# sourceMappingURL=startServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/startServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAC9B,oEAA6C;AAC7C,gEAAyC;AACzC,4DAAqC;AACrC,sDAAgC;AAChC,kEAA2C;AAC3C,oDAA8B;AAC9B,kFAA0D;AAC1D,kFAA0D;AAC1D,6BAA6D;AAC7D,uCAA6D;AAC7D,oDAQ+B;AAC/B,2CAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/startServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AA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,CAAC,MAAM,CAAC,IAAI,EAAE;QAClB,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE;YAC3B,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;SAC1D;QAED,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,oCAA6B,IAAI,CAAE,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/generated/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Load Dependency Source Graphs */
|
|
2
2
|
|
|
3
3
|
import '@pmmmwh/react-refresh-webpack-plugin';
|
|
4
|
+
import '@proteinjs/logger';
|
|
4
5
|
import '@proteinjs/reflection';
|
|
5
6
|
import '@proteinjs/server-api';
|
|
6
|
-
import '@proteinjs/util';
|
|
7
7
|
import '@proteinjs/util-node';
|
|
8
8
|
import 'body-parser';
|
|
9
9
|
import 'buffer';
|
|
@@ -36,7 +36,7 @@ import 'webpack-hot-middleware';
|
|
|
36
36
|
|
|
37
37
|
/** Generate Source Graph */
|
|
38
38
|
|
|
39
|
-
const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/server/NodeGlobalDataStorage\",\"value\":{\"packageName\":\"@proteinjs/server\",\"name\":\"NodeGlobalDataStorage\",\"filePath\":\"/Users/
|
|
39
|
+
const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/server/NodeGlobalDataStorage\",\"value\":{\"packageName\":\"@proteinjs/server\",\"name\":\"NodeGlobalDataStorage\",\"filePath\":\"/Users/brentbahry/workspaces/n3xa/packages/proteinjs/packages/server/packages/server/src/NodeGlobalDataStorage.ts\",\"qualifiedName\":\"@proteinjs/server/NodeGlobalDataStorage\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"HOOK_INITIALIZED\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":true,\"visibility\":\"private\"},{\"name\":\"GLOBAL_DATA\",\"type\":{\"packageName\":\"@proteinjs/server\",\"name\":\"{ [id: string]: GlobalData }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server/{ [id: string]: GlobalData }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":true,\"visibility\":\"private\"},{\"name\":\"environment\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"setData\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"data\",\"type\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"GlobalData\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/GlobalData\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getData\",\"returnType\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"GlobalData\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/GlobalData\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]},{\"name\":\"initHook\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"GlobalDataStorage\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/GlobalDataStorage\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/GlobalDataStorage\"},{\"v\":\"@proteinjs/server/NodeSessionDataStorage\",\"value\":{\"packageName\":\"@proteinjs/server\",\"name\":\"NodeSessionDataStorage\",\"filePath\":\"/Users/brentbahry/workspaces/n3xa/packages/proteinjs/packages/server/packages/server/src/NodeSessionDataStorage.ts\",\"qualifiedName\":\"@proteinjs/server/NodeSessionDataStorage\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"HOOK_INITIALIZED\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":true,\"visibility\":\"private\"},{\"name\":\"SESSION_DATA\",\"type\":{\"packageName\":\"@proteinjs/server\",\"name\":\"{ [id: string]: SessionData }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server/{ [id: string]: SessionData }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":true,\"visibility\":\"private\"},{\"name\":\"environment\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"setData\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"data\",\"type\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"SessionData\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/SessionData\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getData\",\"returnType\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"SessionData\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/SessionData\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]},{\"name\":\"initHook\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"SessionDataStorage\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/SessionDataStorage\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/SessionDataStorage\"},{\"v\":\"@proteinjs/server/environmentCache\",\"value\":{\"packageName\":\"@proteinjs/server\",\"name\":\"environmentCache\",\"filePath\":\"/Users/brentbahry/workspaces/n3xa/packages/proteinjs/packages/server/packages/server/src/envCache.ts\",\"qualifiedName\":\"@proteinjs/server/environmentCache\",\"type\":{\"packageName\":\"\",\"name\":\"GlobalDataCache<Env>\",\"filePath\":null,\"qualifiedName\":\"/GlobalDataCache<Env>\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"GlobalDataCache\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/GlobalDataCache\",\"typeParameters\":[\"@proteinjs/server-api/Env\"],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/server-api/GlobalDataCache\"},{\"v\":\"/string\"},{\"v\":\"@proteinjs/server/healthCheck\",\"value\":{\"packageName\":\"@proteinjs/server\",\"name\":\"healthCheck\",\"filePath\":\"/Users/brentbahry/workspaces/n3xa/packages/proteinjs/packages/server/packages/server/src/routes/healthCheck.ts\",\"qualifiedName\":\"@proteinjs/server/healthCheck\",\"type\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/server/NodeGlobalDataStorage\",\"w\":\"@proteinjs/server-api/GlobalDataStorage\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/server/NodeSessionDataStorage\",\"w\":\"@proteinjs/server-api/SessionDataStorage\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/server/environmentCache\",\"w\":\"@proteinjs/server-api/GlobalDataCache\",\"value\":\"has type\"},{\"v\":\"@proteinjs/server/healthCheck\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"has type\"}]}";
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
/** Generate Source Links */
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "A server impl",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.11",
|
|
25
|
-
"@proteinjs/
|
|
26
|
-
"@proteinjs/
|
|
27
|
-
"@proteinjs/
|
|
28
|
-
"@proteinjs/util-node": "1.4.
|
|
25
|
+
"@proteinjs/logger": "1.0.5",
|
|
26
|
+
"@proteinjs/reflection": "1.1.9",
|
|
27
|
+
"@proteinjs/server-api": "^1.4.3",
|
|
28
|
+
"@proteinjs/util-node": "1.4.1",
|
|
29
29
|
"body-parser": "1.19.0",
|
|
30
30
|
"buffer": "6.0.3",
|
|
31
31
|
"cookie-parser": "1.4.5",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"webpack-hot-middleware": "2.26.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@proteinjs/reflection-build": "1.0.
|
|
58
|
+
"@proteinjs/reflection-build": "1.0.24",
|
|
59
59
|
"@types/body-parser": "1.19.0",
|
|
60
60
|
"@types/cookie-parser": "1.4.2",
|
|
61
61
|
"@types/express": "4.17.7",
|
|
@@ -74,4 +74,4 @@
|
|
|
74
74
|
},
|
|
75
75
|
"main": "./dist/generated/index.js",
|
|
76
76
|
"types": "./dist/generated/index.d.ts"
|
|
77
|
-
}
|
|
77
|
+
}
|
package/src/Request.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import asyncHooks from 'async_hooks';
|
|
2
|
+
|
|
3
|
+
export type RequestMetadata = {
|
|
4
|
+
number: number;
|
|
5
|
+
id: string;
|
|
6
|
+
url: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export class Request {
|
|
10
|
+
private static HOOK_INITIALIZED = false;
|
|
11
|
+
private static readonly REQUEST_METADATA: { [id: string]: RequestMetadata } = {};
|
|
12
|
+
|
|
13
|
+
setMetadata(data: RequestMetadata) {
|
|
14
|
+
if (!Request.HOOK_INITIALIZED) {
|
|
15
|
+
this.initHook();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Request.REQUEST_METADATA[asyncHooks.executionAsyncId()]) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Request.REQUEST_METADATA[asyncHooks.executionAsyncId()] = data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getMetadata(): RequestMetadata {
|
|
26
|
+
if (!Request.HOOK_INITIALIZED) {
|
|
27
|
+
this.initHook();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return Request.REQUEST_METADATA[asyncHooks.executionAsyncId()];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private initHook() {
|
|
34
|
+
asyncHooks
|
|
35
|
+
.createHook({
|
|
36
|
+
init: (asyncId: number, type: string, triggerAsyncId: number, resource: Object) => {
|
|
37
|
+
if (!Request.REQUEST_METADATA[triggerAsyncId]) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Request.REQUEST_METADATA[asyncId] = Request.REQUEST_METADATA[triggerAsyncId];
|
|
42
|
+
},
|
|
43
|
+
destroy: (asyncId: number) => {
|
|
44
|
+
delete Request.REQUEST_METADATA[asyncId];
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
.enable();
|
|
48
|
+
Request.HOOK_INITIALIZED = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/loadRoutes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import
|
|
2
|
+
import crypto from 'crypto';
|
|
3
3
|
import {
|
|
4
4
|
ServerConfig,
|
|
5
5
|
Route,
|
|
@@ -9,15 +9,17 @@ import {
|
|
|
9
9
|
getSessionDataCaches,
|
|
10
10
|
} from '@proteinjs/server-api';
|
|
11
11
|
import { createReactApp } from './routes/reactApp';
|
|
12
|
-
import { Logger } from '@proteinjs/
|
|
12
|
+
import { Logger } from '@proteinjs/logger';
|
|
13
|
+
import { Request } from './Request';
|
|
13
14
|
|
|
14
|
-
const logger = new Logger('Server');
|
|
15
|
+
const logger = new Logger({ name: 'Server' });
|
|
16
|
+
let requestCounter: number = 0;
|
|
15
17
|
|
|
16
18
|
export function loadRoutes(routes: Route[], server: express.Express, config: ServerConfig) {
|
|
17
19
|
let starRoute: Route | null = null;
|
|
18
20
|
const wildcardRoutes: Route[] = [];
|
|
19
21
|
for (const route of routes) {
|
|
20
|
-
logger.info(`Loading route: ${route.path}`);
|
|
22
|
+
logger.info({ message: `Loading route: ${route.path}` });
|
|
21
23
|
if (route.path == '*') {
|
|
22
24
|
starRoute = route;
|
|
23
25
|
continue;
|
|
@@ -54,7 +56,7 @@ export function loadDefaultStarRoute(routes: Route[], server: express.Express, c
|
|
|
54
56
|
|
|
55
57
|
if (!starRouteSpecified && (config.staticContent?.bundlePaths || config.staticContent?.bundlesDir)) {
|
|
56
58
|
const reactApp = createReactApp(config);
|
|
57
|
-
server[reactApp.method](reactApp.path, wrapRoute(reactApp.onRequest, config));
|
|
59
|
+
server[reactApp.method](reactApp.path, wrapRoute(reactApp.onRequest.bind(reactApp), config));
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -72,47 +74,34 @@ function wrapRoute(
|
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
passport.authenticate('local', function (err, user, info) {
|
|
78
|
-
if (err) {
|
|
79
|
-
reject(err);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
resolve();
|
|
83
|
-
})(request, response, next);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
77
|
+
const requestNumber = ++requestCounter;
|
|
78
|
+
const requestId = crypto.randomBytes(8).toString('hex');
|
|
86
79
|
|
|
80
|
+
// Set metadata into request async-hook storage
|
|
81
|
+
new Request().setMetadata({
|
|
82
|
+
number: requestNumber,
|
|
83
|
+
id: requestId,
|
|
84
|
+
url: request.originalUrl,
|
|
85
|
+
});
|
|
87
86
|
const sessionData: SessionData = { sessionId: request.sessionID, user: request.user as string, data: {} };
|
|
88
87
|
for (const sessionDataCache of getSessionDataCaches()) {
|
|
89
88
|
sessionData.data[sessionDataCache.key] = await sessionDataCache.create(sessionData.sessionId, sessionData.user);
|
|
90
89
|
}
|
|
91
90
|
Session.setData(sessionData);
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
await listener.beforeRequest(request, response);
|
|
101
|
-
} catch (error: any) {
|
|
102
|
-
logger.error(`Caught error when running listener before request`, error);
|
|
92
|
+
if (shouldLogRequest(request, config)) {
|
|
93
|
+
let message = `Started ${request.originalUrl}`;
|
|
94
|
+
if (process.env.DEVELOPMENT) {
|
|
95
|
+
message = `[#${requestNumber}] ${message}`;
|
|
103
96
|
}
|
|
97
|
+
logger.info({ message });
|
|
104
98
|
}
|
|
105
99
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
request
|
|
109
|
-
if (response.locals.requestNumber) {
|
|
110
|
-
logger.warn(`[#${response.locals.requestNumber}] Timed out ${request.originalUrl}`);
|
|
111
|
-
} else {
|
|
112
|
-
logger.warn(`Timed out ${request.originalUrl}`);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
100
|
+
await runBeforeRequestListeners(request, response);
|
|
101
|
+
|
|
102
|
+
setRequestTimeout(request, config, requestNumber);
|
|
115
103
|
|
|
104
|
+
// Run route
|
|
116
105
|
try {
|
|
117
106
|
await route(request, response);
|
|
118
107
|
} catch (error) {
|
|
@@ -120,28 +109,70 @@ function wrapRoute(
|
|
|
120
109
|
}
|
|
121
110
|
response.locals['responseHandled'] = true;
|
|
122
111
|
|
|
123
|
-
|
|
124
|
-
if (!listener.afterRequest) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
112
|
+
await runAfterRequestListeners(request, response);
|
|
127
113
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
114
|
+
if (shouldLogRequest(request, config)) {
|
|
115
|
+
let message = `Finished ${request.originalUrl}`;
|
|
116
|
+
if (process.env.DEVELOPMENT) {
|
|
117
|
+
message = `[#${requestNumber}] ${message}`;
|
|
132
118
|
}
|
|
119
|
+
logger.info({ message });
|
|
133
120
|
}
|
|
134
121
|
|
|
135
122
|
next();
|
|
136
123
|
};
|
|
137
124
|
}
|
|
138
125
|
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
126
|
+
function shouldLogRequest(request: express.Request, config: ServerConfig) {
|
|
127
|
+
if (config.request?.disableRequestLogging) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (request.path.startsWith('/static') || request.path.startsWith('/favicon.ico')) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function setRequestTimeout(request: express.Request, config: ServerConfig, requestNumber: number) {
|
|
139
|
+
const sixtyMinutes = 1000 * 60 * 60;
|
|
140
|
+
const timeout = typeof config.request?.timeoutMs !== 'undefined' ? config.request.timeoutMs : sixtyMinutes;
|
|
141
|
+
request.setTimeout(timeout, () => {
|
|
142
|
+
let message = `Timed out ${request.originalUrl}`;
|
|
143
|
+
if (process.env.DEVELOPMENT) {
|
|
144
|
+
message = `[#${requestNumber}] ${message}`;
|
|
145
|
+
}
|
|
146
|
+
logger.warn({ message });
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function runBeforeRequestListeners(request: express.Request, response: express.Response) {
|
|
151
|
+
const requestListeners = getRequestListeners();
|
|
152
|
+
for (const listener of requestListeners) {
|
|
153
|
+
if (!listener.beforeRequest) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
await listener.beforeRequest(request, response);
|
|
159
|
+
} catch (error: any) {
|
|
160
|
+
logger.error({ message: `Caught error when running listener before request`, error });
|
|
161
|
+
}
|
|
144
162
|
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function runAfterRequestListeners(request: express.Request, response: express.Response) {
|
|
166
|
+
const requestListeners = getRequestListeners();
|
|
167
|
+
for (const listener of requestListeners) {
|
|
168
|
+
if (!listener.afterRequest) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
145
171
|
|
|
146
|
-
|
|
172
|
+
try {
|
|
173
|
+
await listener.afterRequest(request, response);
|
|
174
|
+
} catch (error: any) {
|
|
175
|
+
logger.error({ message: `Caught error when running listener after request`, error });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
147
178
|
}
|