@proteinjs/server 1.4.5 → 1.5.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 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +2 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/startServer.d.ts +2 -0
- package/dist/src/startServer.d.ts.map +1 -1
- package/dist/src/startServer.js +85 -37
- package/dist/src/startServer.js.map +1 -1
- package/generated/index.ts +2 -1
- package/package.json +4 -3
- package/src/startServer.ts +102 -36
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.5.0](https://github.com/proteinjs/server/compare/@proteinjs/server@1.4.5...@proteinjs/server@1.5.0) (2024-07-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* added support for Socket.IO ([77c29a4](https://github.com/proteinjs/server/commit/77c29a4ddfd190f50ee38a0f80e118700eb417e0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [1.4.0](https://github.com/proteinjs/server/compare/@proteinjs/server@1.3.7...@proteinjs/server@1.4.0) (2024-07-06)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,sCAAsC,CAAC;AAC9C,OAAO,eAAe,CAAC;AACvB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,iBAAiB,CAAC;AACzB,OAAO,sBAAsB,CAAC;AAC9B,OAAO,aAAa,CAAC;AAC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AO,iBAAiB,CAAC;AACzB,OAAO,SAAS,CAAC;AACjB,OAAO,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,eAAe,CAAC;AACvB,OAAO,0BAA0B,CAAC;AAClC,OAAO,WAAW,CAAC;AACnB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,cAAc,CAAC;AACtB,OAAO,WAAW,CAAC;AACnB,OAAO,YAAY,CAAC;AACpB,OAAO,KAAK,CAAC;AACb,OAAO,MAAM,CAAC;AACd,OAAO,SAAS,CAAC;AACjB,OAAO,wBAAwB,CAAC;AAChC,OAAO,wBAAwB,CAAC;AA6BhC,cAAc,UAAU,CAAC"}
|
package/dist/generated/index.js
CHANGED
|
@@ -39,6 +39,7 @@ require("react");
|
|
|
39
39
|
require("react-helmet");
|
|
40
40
|
require("react-refresh");
|
|
41
41
|
require("react-refresh-typescript");
|
|
42
|
+
require("socket.io");
|
|
42
43
|
require("stream-browserify");
|
|
43
44
|
require("style-loader");
|
|
44
45
|
require("ts-loader");
|
|
@@ -49,7 +50,7 @@ require("webpack");
|
|
|
49
50
|
require("webpack-dev-middleware");
|
|
50
51
|
require("webpack-hot-middleware");
|
|
51
52
|
/** Generate Source Graph */
|
|
52
|
-
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/server/NodeGlobalDataStorage\",\"value\":{\"packageName\":\"@proteinjs/server\",\"name\":\"NodeGlobalDataStorage\",\"filePath\":\"/Users/
|
|
53
|
+
var 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\"}]}";
|
|
53
54
|
/** Generate Source Links */
|
|
54
55
|
var NodeGlobalDataStorage_1 = require("../src/NodeGlobalDataStorage");
|
|
55
56
|
var NodeSessionDataStorage_1 = require("../src/NodeSessionDataStorage");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,gDAA8C;AAC9C,yBAAuB;AACvB,iCAA+B;AAC/B,iCAA+B;AAC/B,2BAAyB;AACzB,gCAA8B;AAC9B,uBAAqB;AACrB,kBAAgB;AAChB,uBAAqB;AACrB,yBAAuB;AACvB,6BAA2B;AAC3B,sBAAoB;AACpB,kBAAgB;AAChB,mBAAiB;AACjB,2BAAyB;AACzB,uBAAqB;AACrB,oBAAkB;AAClB,0BAAwB;AACxB,2BAAyB;AACzB,mBAAiB;AACjB,iBAAe;AACf,wBAAsB;AACtB,yBAAuB;AACvB,oCAAkC;AAClC,6BAA2B;AAC3B,wBAAsB;AACtB,qBAAmB;AACnB,sBAAoB;AACpB,eAAa;AACb,gBAAc;AACd,mBAAiB;AACjB,kCAAgC;AAChC,kCAAgC;AAGhC,4BAA4B;AAE5B,IAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,gDAA8C;AAC9C,yBAAuB;AACvB,iCAA+B;AAC/B,iCAA+B;AAC/B,2BAAyB;AACzB,gCAA8B;AAC9B,uBAAqB;AACrB,kBAAgB;AAChB,uBAAqB;AACrB,yBAAuB;AACvB,6BAA2B;AAC3B,sBAAoB;AACpB,kBAAgB;AAChB,mBAAiB;AACjB,2BAAyB;AACzB,uBAAqB;AACrB,oBAAkB;AAClB,0BAAwB;AACxB,2BAAyB;AACzB,mBAAiB;AACjB,iBAAe;AACf,wBAAsB;AACtB,yBAAuB;AACvB,oCAAkC;AAClC,qBAAmB;AACnB,6BAA2B;AAC3B,wBAAsB;AACtB,qBAAmB;AACnB,sBAAoB;AACpB,eAAa;AACb,gBAAc;AACd,mBAAiB;AACjB,kCAAgC;AAChC,kCAAgC;AAGhC,4BAA4B;AAE5B,IAAM,WAAW,GAAG,ooNAAooN,CAAC;AAGzpN,4BAA4B;AAE5B,sEAAqE;AACrE,wEAAuE;AACvE,4CAAmD;AACnD,yDAAwD;AAExD,IAAM,WAAW,GAAG;IACnB,yCAAyC,EAAE,6CAAqB;IAChE,0CAA0C,EAAE,+CAAsB;IAClE,oCAAoC,EAAE,2BAAgB;IACtD,+BAA+B,EAAE,yBAAW;CAC5C,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Server as SocketIOServer } from 'socket.io';
|
|
1
2
|
import { ServerConfig } from '@proteinjs/server-api';
|
|
3
|
+
export declare const io: SocketIOServer<import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, any>;
|
|
2
4
|
export declare function startServer(config: ServerConfig): Promise<void>;
|
|
3
5
|
//# sourceMappingURL=startServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startServer.d.ts","sourceRoot":"","sources":["../../src/startServer.ts"],"names":[],"mappings":"AAWA,OAAO,EAAsB,YAAY,EAAkC,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"startServer.d.ts","sourceRoot":"","sources":["../../src/startServer.ts"],"names":[],"mappings":"AAWA,OAAO,EAAU,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAsB,YAAY,EAAkC,MAAM,uBAAuB,CAAC;AAkBzG,eAAO,MAAM,EAAE,6LAA6B,CAAC;AAE7C,wBAAsB,WAAW,CAAC,MAAM,EAAE,YAAY,iBA8BrD"}
|
package/dist/src/startServer.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.startServer = void 0;
|
|
42
|
+
exports.startServer = exports.io = void 0;
|
|
43
43
|
var express_1 = __importDefault(require("express"));
|
|
44
44
|
var express_session_1 = __importDefault(require("express-session"));
|
|
45
45
|
var compression_1 = __importDefault(require("compression"));
|
|
@@ -50,6 +50,8 @@ var passport_local_1 = __importDefault(require("passport-local"));
|
|
|
50
50
|
var webpack_1 = __importDefault(require("webpack"));
|
|
51
51
|
var webpack_dev_middleware_1 = __importDefault(require("webpack-dev-middleware"));
|
|
52
52
|
var webpack_hot_middleware_1 = __importDefault(require("webpack-hot-middleware"));
|
|
53
|
+
var http_1 = require("http");
|
|
54
|
+
var socket_io_1 = require("socket.io");
|
|
53
55
|
var db_1 = require("@proteinjs/db");
|
|
54
56
|
var server_api_1 = require("@proteinjs/server-api");
|
|
55
57
|
var loadRoutes_1 = require("./loadRoutes");
|
|
@@ -57,9 +59,12 @@ var util_1 = require("@proteinjs/util");
|
|
|
57
59
|
var nodeModulesPath_1 = require("./nodeModulesPath");
|
|
58
60
|
var staticContentPath = '/static/';
|
|
59
61
|
var logger = new util_1.Logger('Server');
|
|
62
|
+
var app = (0, express_1.default)();
|
|
63
|
+
var server = new http_1.Server(app);
|
|
64
|
+
exports.io = new socket_io_1.Server(server);
|
|
60
65
|
function startServer(config) {
|
|
61
66
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
-
var routes,
|
|
67
|
+
var routes, globalData, _i, _a, globalDataCache, _b, _c;
|
|
63
68
|
return __generator(this, function (_d) {
|
|
64
69
|
switch (_d.label) {
|
|
65
70
|
case 0:
|
|
@@ -67,15 +72,14 @@ function startServer(config) {
|
|
|
67
72
|
return [4 /*yield*/, runStartupEvents(config)];
|
|
68
73
|
case 1:
|
|
69
74
|
_d.sent();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(0, loadRoutes_1.loadRoutes)(routes.filter(function (route) { return !route.useHttp; }), server, config);
|
|
75
|
+
configureRequests(app);
|
|
76
|
+
initializeHotReloading(app, config);
|
|
77
|
+
beforeRequest(app, config);
|
|
78
|
+
(0, loadRoutes_1.loadRoutes)(routes.filter(function (route) { return route.useHttp; }), app, config);
|
|
79
|
+
configureHttps(app); // registering here forces static content to be redirected to https
|
|
80
|
+
configureStaticContentRouter(app, config); // registering here prevents sessions from being created on static content requests
|
|
81
|
+
configureSession(app, config);
|
|
82
|
+
(0, loadRoutes_1.loadRoutes)(routes.filter(function (route) { return !route.useHttp; }), app, config);
|
|
79
83
|
globalData = {};
|
|
80
84
|
_i = 0, _a = (0, server_api_1.getGlobalDataCaches)();
|
|
81
85
|
_d.label = 2;
|
|
@@ -93,8 +97,9 @@ function startServer(config) {
|
|
|
93
97
|
return [3 /*break*/, 2];
|
|
94
98
|
case 5:
|
|
95
99
|
server_api_1.Global.setData(globalData);
|
|
96
|
-
(0, loadRoutes_1.loadDefaultStarRoute)(routes,
|
|
97
|
-
afterRequest(
|
|
100
|
+
(0, loadRoutes_1.loadDefaultStarRoute)(routes, app, config);
|
|
101
|
+
afterRequest(app, config);
|
|
102
|
+
initializeSocketIO(exports.io, app);
|
|
98
103
|
start(server, config);
|
|
99
104
|
return [2 /*return*/];
|
|
100
105
|
}
|
|
@@ -119,17 +124,17 @@ function runStartupEvents(config) {
|
|
|
119
124
|
});
|
|
120
125
|
});
|
|
121
126
|
}
|
|
122
|
-
function configureRequests(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
function configureRequests(app) {
|
|
128
|
+
app.use((0, compression_1.default)());
|
|
129
|
+
app.use((0, cookie_parser_1.default)());
|
|
130
|
+
app.use(body_parser_1.default.json({ limit: '100mb' }));
|
|
131
|
+
app.use(body_parser_1.default.urlencoded({
|
|
127
132
|
extended: true,
|
|
128
133
|
limit: '100mb',
|
|
129
134
|
}));
|
|
130
|
-
|
|
135
|
+
app.disable('x-powered-by');
|
|
131
136
|
}
|
|
132
|
-
function initializeHotReloading(
|
|
137
|
+
function initializeHotReloading(app, config) {
|
|
133
138
|
var _a, _b;
|
|
134
139
|
if (!process.env.DEVELOPMENT ||
|
|
135
140
|
process.env.DISABLE_HOT_CLIENT_BUILDS ||
|
|
@@ -143,10 +148,10 @@ function initializeHotReloading(server, config) {
|
|
|
143
148
|
wpConfig['output']['path'] = config.staticContent.staticContentDir;
|
|
144
149
|
wpConfig['output']['publicPath'] = staticContentPath;
|
|
145
150
|
var webpackCompiler = (0, webpack_1.default)(wpConfig);
|
|
146
|
-
|
|
151
|
+
app.use((0, webpack_dev_middleware_1.default)(webpackCompiler, {
|
|
147
152
|
publicPath: staticContentPath,
|
|
148
153
|
}));
|
|
149
|
-
|
|
154
|
+
app.use((0, webpack_hot_middleware_1.default)(webpackCompiler));
|
|
150
155
|
}
|
|
151
156
|
function getWebpackConfig(config) {
|
|
152
157
|
var _a;
|
|
@@ -154,8 +159,8 @@ function getWebpackConfig(config) {
|
|
|
154
159
|
var webpackConfig = require('../webpack.config');
|
|
155
160
|
return webpackConfig;
|
|
156
161
|
}
|
|
157
|
-
function configureHttps(
|
|
158
|
-
|
|
162
|
+
function configureHttps(app) {
|
|
163
|
+
app.use(function (request, response, next) {
|
|
159
164
|
if (request.protocol == 'https' || response.headersSent || process.env.DEVELOPMENT) {
|
|
160
165
|
next();
|
|
161
166
|
return;
|
|
@@ -164,15 +169,15 @@ function configureHttps(server) {
|
|
|
164
169
|
response.redirect('https://' + request.headers.host + request.url);
|
|
165
170
|
});
|
|
166
171
|
}
|
|
167
|
-
function configureStaticContentRouter(
|
|
172
|
+
function configureStaticContentRouter(app, config) {
|
|
168
173
|
var _a;
|
|
169
174
|
if (!((_a = config.staticContent) === null || _a === void 0 ? void 0 : _a.staticContentDir)) {
|
|
170
175
|
return;
|
|
171
176
|
}
|
|
172
|
-
|
|
177
|
+
app.use(staticContentPath, express_1.default.static(config.staticContent.staticContentDir));
|
|
173
178
|
logger.info("Serving static content on path: ".concat(staticContentPath, ", serving from directory: ").concat(config.staticContent.staticContentDir));
|
|
174
179
|
}
|
|
175
|
-
function configureSession(
|
|
180
|
+
function configureSession(app, config) {
|
|
176
181
|
var sixtyDays = 1000 * 60 * 60 * 24 * 60;
|
|
177
182
|
var sessionOptions = {
|
|
178
183
|
secret: config.session.secret,
|
|
@@ -185,7 +190,7 @@ function configureSession(server, config) {
|
|
|
185
190
|
rolling: true,
|
|
186
191
|
};
|
|
187
192
|
if (!process.env.DEVELOPMENT) {
|
|
188
|
-
|
|
193
|
+
app.set('trust proxy', 1);
|
|
189
194
|
if (!sessionOptions.cookie) {
|
|
190
195
|
sessionOptions.cookie = {};
|
|
191
196
|
}
|
|
@@ -194,9 +199,11 @@ function configureSession(server, config) {
|
|
|
194
199
|
if (config.session) {
|
|
195
200
|
sessionOptions = Object.assign(sessionOptions, config.session);
|
|
196
201
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
var sessionMiddleware = (0, express_session_1.default)(sessionOptions);
|
|
203
|
+
app.use(sessionMiddleware);
|
|
204
|
+
app.use(passport_1.default.initialize());
|
|
205
|
+
app.use(passport_1.default.session());
|
|
206
|
+
app.set('sessionMiddleware', sessionMiddleware); // Store the session middleware in the app for later use
|
|
200
207
|
if (config.authenticate) {
|
|
201
208
|
initializeAuthentication(config.authenticate);
|
|
202
209
|
}
|
|
@@ -227,11 +234,11 @@ function initializeAuthentication(authenticate) {
|
|
|
227
234
|
done(null, id);
|
|
228
235
|
});
|
|
229
236
|
}
|
|
230
|
-
function beforeRequest(
|
|
237
|
+
function beforeRequest(app, config) {
|
|
231
238
|
var _a, _b, _c;
|
|
232
239
|
var requestCounter = 0;
|
|
233
240
|
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') {
|
|
234
|
-
|
|
241
|
+
app.use(function (request, response, next) {
|
|
235
242
|
if (request.path.startsWith('/static') || request.path.startsWith('/favicon.ico')) {
|
|
236
243
|
next();
|
|
237
244
|
return;
|
|
@@ -243,16 +250,16 @@ function beforeRequest(server, config) {
|
|
|
243
250
|
});
|
|
244
251
|
}
|
|
245
252
|
if ((_c = config.request) === null || _c === void 0 ? void 0 : _c.beforeRequest) {
|
|
246
|
-
|
|
253
|
+
app.use(config.request.beforeRequest);
|
|
247
254
|
}
|
|
248
255
|
}
|
|
249
|
-
function afterRequest(
|
|
256
|
+
function afterRequest(app, config) {
|
|
250
257
|
var _a, _b, _c;
|
|
251
258
|
if ((_a = config.request) === null || _a === void 0 ? void 0 : _a.afterRequest) {
|
|
252
|
-
|
|
259
|
+
app.use(config.request.afterRequest);
|
|
253
260
|
}
|
|
254
261
|
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') {
|
|
255
|
-
|
|
262
|
+
app.use(function (request, response, next) {
|
|
256
263
|
if (request.path.startsWith('/static') || request.path.startsWith('/favicon.ico')) {
|
|
257
264
|
next();
|
|
258
265
|
return;
|
|
@@ -262,6 +269,47 @@ function afterRequest(server, config) {
|
|
|
262
269
|
});
|
|
263
270
|
}
|
|
264
271
|
}
|
|
272
|
+
function initializeSocketIO(io, app) {
|
|
273
|
+
var logger = new util_1.Logger('SocketIOServer');
|
|
274
|
+
// Share session and passport middleware with Socket.IO
|
|
275
|
+
var wrapMiddleware = function (middleware) { return function (socket, next) { return middleware(socket.request, {}, next); }; };
|
|
276
|
+
var sessionMiddleware = app.get('sessionMiddleware');
|
|
277
|
+
io.use(wrapMiddleware(sessionMiddleware));
|
|
278
|
+
io.use(wrapMiddleware(passport_1.default.initialize()));
|
|
279
|
+
io.use(wrapMiddleware(passport_1.default.session()));
|
|
280
|
+
// Use passport for authentication with Socket.IO
|
|
281
|
+
io.use(function (socket, next) {
|
|
282
|
+
if (socket.request.user) {
|
|
283
|
+
next();
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
next(new Error('Unauthorized'));
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
// Initialize Socket.IO event handlers
|
|
290
|
+
io.on('connection', function (socket) {
|
|
291
|
+
var userInfo = "".concat(socket.request.user, " (").concat(socket.id, ")");
|
|
292
|
+
logger.info("User connected: ".concat(userInfo));
|
|
293
|
+
// Map this socket to the session id so it can be closed when the session is destroyed
|
|
294
|
+
var sessionId = socket.request.sessionID;
|
|
295
|
+
if (sessionId) {
|
|
296
|
+
socket.join(sessionId);
|
|
297
|
+
}
|
|
298
|
+
socket.on('disconnect', function (reason) {
|
|
299
|
+
logger.info("User disconnected: ".concat(userInfo, ". Reason: ").concat(reason));
|
|
300
|
+
});
|
|
301
|
+
socket.on('error', function (error) {
|
|
302
|
+
logger.error("Socket error for user: ".concat(userInfo, ". Error:"), error);
|
|
303
|
+
});
|
|
304
|
+
socket.conn.on('error', function (error) {
|
|
305
|
+
logger.error("Socket connection error for user: ".concat(userInfo, ". Error:"), error);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
// Handle server-level errors
|
|
309
|
+
io.engine.on('connection_error', function (err) {
|
|
310
|
+
logger.error('Connection error:', err);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
265
313
|
function start(server, config) {
|
|
266
314
|
var port = config.port ? config.port : 3000;
|
|
267
315
|
server.listen(port, function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/startServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAC9B,oEAA6C;AAC7C,4DAAsC;AACtC,gEAAyC;AACzC,4DAAqC;AACrC,sDAAgC;AAChC,kEAA2C;AAC3C,oDAA8B;AAC9B,kFAA0D;AAC1D,kFAA0D;AAC1D,oCAAmC;AACnC,oDAAyG;AACzG,2CAAgE;AAChE,wCAAyC;AACzC,qDAAuD;
|
|
1
|
+
{"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/startServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAC9B,oEAA6C;AAC7C,4DAAsC;AACtC,gEAAyC;AACzC,4DAAqC;AACrC,sDAAgC;AAChC,kEAA2C;AAC3C,oDAA8B;AAC9B,kFAA0D;AAC1D,kFAA0D;AAC1D,6BAA6D;AAC7D,uCAA6D;AAC7D,oCAAmC;AACnC,oDAAyG;AACzG,2CAAgE;AAChE,wCAAyC;AACzC,qDAAuD;AAWvD,IAAM,iBAAiB,GAAG,UAAU,CAAC;AACrC,IAAM,MAAM,GAAG,IAAI,aAAM,CAAC,QAAQ,CAAC,CAAC;AACpC,IAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,IAAM,MAAM,GAAG,IAAI,aAAU,CAAC,GAAG,CAAC,CAAC;AACtB,QAAA,EAAE,GAAG,IAAI,kBAAc,CAAC,MAAM,CAAC,CAAC;AAE7C,SAAsB,WAAW,CAAC,MAAoB;;;;;;oBAC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CAA6B,IAAI,CAAE,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/generated/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import 'react';
|
|
|
24
24
|
import 'react-helmet';
|
|
25
25
|
import 'react-refresh';
|
|
26
26
|
import 'react-refresh-typescript';
|
|
27
|
+
import 'socket.io';
|
|
27
28
|
import 'stream-browserify';
|
|
28
29
|
import 'style-loader';
|
|
29
30
|
import 'ts-loader';
|
|
@@ -37,7 +38,7 @@ import 'webpack-hot-middleware';
|
|
|
37
38
|
|
|
38
39
|
/** Generate Source Graph */
|
|
39
40
|
|
|
40
|
-
const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/server/NodeGlobalDataStorage\",\"value\":{\"packageName\":\"@proteinjs/server\",\"name\":\"NodeGlobalDataStorage\",\"filePath\":\"/Users/
|
|
41
|
+
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\"}]}";
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
/** Generate Source Links */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A server impl",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.11",
|
|
25
|
-
"@proteinjs/db": "1.3.
|
|
25
|
+
"@proteinjs/db": "1.3.3",
|
|
26
26
|
"@proteinjs/reflection": "1.1.7",
|
|
27
|
-
"@proteinjs/server-api": "^1.3.
|
|
27
|
+
"@proteinjs/server-api": "^1.3.5",
|
|
28
28
|
"@proteinjs/util": "1.3.1",
|
|
29
29
|
"@proteinjs/util-node": "1.3.3",
|
|
30
30
|
"body-parser": "1.19.0",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"react-helmet": "6.1.0",
|
|
46
46
|
"react-refresh": "0.14.0",
|
|
47
47
|
"react-refresh-typescript": "2.0.9",
|
|
48
|
+
"socket.io": "4.7.5",
|
|
48
49
|
"stream-browserify": "3.0.0",
|
|
49
50
|
"style-loader": "4.0.0",
|
|
50
51
|
"ts-loader": "8.0.3",
|
package/src/startServer.ts
CHANGED
|
@@ -8,33 +8,46 @@ import passportLocal from 'passport-local';
|
|
|
8
8
|
import webpack from 'webpack';
|
|
9
9
|
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
10
10
|
import webpackHotMiddleware from 'webpack-hot-middleware';
|
|
11
|
+
import { Server as HttpServer, IncomingMessage } from 'http';
|
|
12
|
+
import { Socket, Server as SocketIOServer } from 'socket.io';
|
|
11
13
|
import { Db } from '@proteinjs/db';
|
|
12
14
|
import { Global, GlobalData, ServerConfig, getGlobalDataCaches, getRoutes } from '@proteinjs/server-api';
|
|
13
15
|
import { loadRoutes, loadDefaultStarRoute } from './loadRoutes';
|
|
14
16
|
import { Logger } from '@proteinjs/util';
|
|
15
17
|
import { setNodeModulesPath } from './nodeModulesPath';
|
|
16
18
|
|
|
19
|
+
interface ExtendedIncomingMessage extends IncomingMessage {
|
|
20
|
+
sessionID?: string;
|
|
21
|
+
user?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ExtendedSocket extends Socket {
|
|
25
|
+
request: ExtendedIncomingMessage;
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
const staticContentPath = '/static/';
|
|
18
29
|
const logger = new Logger('Server');
|
|
30
|
+
const app = express();
|
|
31
|
+
const server = new HttpServer(app);
|
|
32
|
+
export const io = new SocketIOServer(server);
|
|
19
33
|
|
|
20
34
|
export async function startServer(config: ServerConfig) {
|
|
21
35
|
const routes = getRoutes();
|
|
22
36
|
await runStartupEvents(config);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
beforeRequest(server, config);
|
|
37
|
+
configureRequests(app);
|
|
38
|
+
initializeHotReloading(app, config);
|
|
39
|
+
beforeRequest(app, config);
|
|
27
40
|
loadRoutes(
|
|
28
41
|
routes.filter((route) => route.useHttp),
|
|
29
|
-
|
|
42
|
+
app,
|
|
30
43
|
config
|
|
31
44
|
);
|
|
32
|
-
configureHttps(
|
|
33
|
-
configureStaticContentRouter(
|
|
34
|
-
configureSession(
|
|
45
|
+
configureHttps(app); // registering here forces static content to be redirected to https
|
|
46
|
+
configureStaticContentRouter(app, config); // registering here prevents sessions from being created on static content requests
|
|
47
|
+
configureSession(app, config);
|
|
35
48
|
loadRoutes(
|
|
36
49
|
routes.filter((route) => !route.useHttp),
|
|
37
|
-
|
|
50
|
+
app,
|
|
38
51
|
config
|
|
39
52
|
);
|
|
40
53
|
|
|
@@ -44,8 +57,9 @@ export async function startServer(config: ServerConfig) {
|
|
|
44
57
|
}
|
|
45
58
|
Global.setData(globalData);
|
|
46
59
|
|
|
47
|
-
loadDefaultStarRoute(routes,
|
|
48
|
-
afterRequest(
|
|
60
|
+
loadDefaultStarRoute(routes, app, config);
|
|
61
|
+
afterRequest(app, config);
|
|
62
|
+
initializeSocketIO(io, app);
|
|
49
63
|
start(server, config);
|
|
50
64
|
}
|
|
51
65
|
|
|
@@ -57,20 +71,20 @@ async function runStartupEvents(config: ServerConfig) {
|
|
|
57
71
|
}
|
|
58
72
|
}
|
|
59
73
|
|
|
60
|
-
function configureRequests(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
function configureRequests(app: express.Express) {
|
|
75
|
+
app.use(compression());
|
|
76
|
+
app.use(cookieParser());
|
|
77
|
+
app.use(bodyParser.json({ limit: '100mb' }));
|
|
78
|
+
app.use(
|
|
65
79
|
bodyParser.urlencoded({
|
|
66
80
|
extended: true,
|
|
67
81
|
limit: '100mb',
|
|
68
82
|
})
|
|
69
83
|
);
|
|
70
|
-
|
|
84
|
+
app.disable('x-powered-by');
|
|
71
85
|
}
|
|
72
86
|
|
|
73
|
-
function initializeHotReloading(
|
|
87
|
+
function initializeHotReloading(app: express.Express, config: ServerConfig) {
|
|
74
88
|
if (
|
|
75
89
|
!process.env.DEVELOPMENT ||
|
|
76
90
|
process.env.DISABLE_HOT_CLIENT_BUILDS ||
|
|
@@ -86,12 +100,12 @@ function initializeHotReloading(server: express.Express, config: ServerConfig) {
|
|
|
86
100
|
wpConfig['output']['path'] = config.staticContent.staticContentDir;
|
|
87
101
|
wpConfig['output']['publicPath'] = staticContentPath;
|
|
88
102
|
const webpackCompiler = webpack(wpConfig);
|
|
89
|
-
|
|
103
|
+
app.use(
|
|
90
104
|
webpackDevMiddleware(webpackCompiler, {
|
|
91
105
|
publicPath: staticContentPath,
|
|
92
106
|
})
|
|
93
107
|
);
|
|
94
|
-
|
|
108
|
+
app.use(webpackHotMiddleware(webpackCompiler));
|
|
95
109
|
}
|
|
96
110
|
|
|
97
111
|
function getWebpackConfig(config: ServerConfig) {
|
|
@@ -100,8 +114,8 @@ function getWebpackConfig(config: ServerConfig) {
|
|
|
100
114
|
return webpackConfig;
|
|
101
115
|
}
|
|
102
116
|
|
|
103
|
-
function configureHttps(
|
|
104
|
-
|
|
117
|
+
function configureHttps(app: express.Express) {
|
|
118
|
+
app.use((request: express.Request, response: express.Response, next: express.NextFunction) => {
|
|
105
119
|
if (request.protocol == 'https' || response.headersSent || process.env.DEVELOPMENT) {
|
|
106
120
|
next();
|
|
107
121
|
return;
|
|
@@ -112,18 +126,18 @@ function configureHttps(server: express.Express) {
|
|
|
112
126
|
});
|
|
113
127
|
}
|
|
114
128
|
|
|
115
|
-
function configureStaticContentRouter(
|
|
129
|
+
function configureStaticContentRouter(app: express.Express, config: ServerConfig) {
|
|
116
130
|
if (!config.staticContent?.staticContentDir) {
|
|
117
131
|
return;
|
|
118
132
|
}
|
|
119
133
|
|
|
120
|
-
|
|
134
|
+
app.use(staticContentPath, express.static(config.staticContent.staticContentDir));
|
|
121
135
|
logger.info(
|
|
122
136
|
`Serving static content on path: ${staticContentPath}, serving from directory: ${config.staticContent.staticContentDir}`
|
|
123
137
|
);
|
|
124
138
|
}
|
|
125
139
|
|
|
126
|
-
function configureSession(
|
|
140
|
+
function configureSession(app: express.Express, config: ServerConfig) {
|
|
127
141
|
const sixtyDays = 1000 * 60 * 60 * 24 * 60;
|
|
128
142
|
let sessionOptions: expressSession.SessionOptions = {
|
|
129
143
|
secret: config.session.secret,
|
|
@@ -137,7 +151,7 @@ function configureSession(server: express.Express, config: ServerConfig) {
|
|
|
137
151
|
};
|
|
138
152
|
|
|
139
153
|
if (!process.env.DEVELOPMENT) {
|
|
140
|
-
|
|
154
|
+
app.set('trust proxy', 1);
|
|
141
155
|
if (!sessionOptions.cookie) {
|
|
142
156
|
sessionOptions.cookie = {};
|
|
143
157
|
}
|
|
@@ -148,9 +162,12 @@ function configureSession(server: express.Express, config: ServerConfig) {
|
|
|
148
162
|
sessionOptions = Object.assign(sessionOptions, config.session);
|
|
149
163
|
}
|
|
150
164
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
165
|
+
const sessionMiddleware = expressSession(sessionOptions);
|
|
166
|
+
app.use(sessionMiddleware);
|
|
167
|
+
app.use(passport.initialize());
|
|
168
|
+
app.use(passport.session());
|
|
169
|
+
app.set('sessionMiddleware', sessionMiddleware); // Store the session middleware in the app for later use
|
|
170
|
+
|
|
154
171
|
if (config.authenticate) {
|
|
155
172
|
initializeAuthentication(config.authenticate);
|
|
156
173
|
}
|
|
@@ -178,10 +195,10 @@ function initializeAuthentication(authenticate: (username: string, password: str
|
|
|
178
195
|
});
|
|
179
196
|
}
|
|
180
197
|
|
|
181
|
-
function beforeRequest(
|
|
198
|
+
function beforeRequest(app: express.Express, config: ServerConfig) {
|
|
182
199
|
let requestCounter: number = 0;
|
|
183
200
|
if (config.request?.disableRequestLogging == false || typeof config.request?.disableRequestLogging === 'undefined') {
|
|
184
|
-
|
|
201
|
+
app.use((request: express.Request, response: express.Response, next: express.NextFunction) => {
|
|
185
202
|
if (request.path.startsWith('/static') || request.path.startsWith('/favicon.ico')) {
|
|
186
203
|
next();
|
|
187
204
|
return;
|
|
@@ -195,17 +212,17 @@ function beforeRequest(server: express.Express, config: ServerConfig) {
|
|
|
195
212
|
}
|
|
196
213
|
|
|
197
214
|
if (config.request?.beforeRequest) {
|
|
198
|
-
|
|
215
|
+
app.use(config.request.beforeRequest);
|
|
199
216
|
}
|
|
200
217
|
}
|
|
201
218
|
|
|
202
|
-
function afterRequest(
|
|
219
|
+
function afterRequest(app: express.Express, config: ServerConfig) {
|
|
203
220
|
if (config.request?.afterRequest) {
|
|
204
|
-
|
|
221
|
+
app.use(config.request.afterRequest);
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
if (config.request?.disableRequestLogging == false || typeof config.request?.disableRequestLogging === 'undefined') {
|
|
208
|
-
|
|
225
|
+
app.use((request: express.Request, response: express.Response, next: express.NextFunction) => {
|
|
209
226
|
if (request.path.startsWith('/static') || request.path.startsWith('/favicon.ico')) {
|
|
210
227
|
next();
|
|
211
228
|
return;
|
|
@@ -217,7 +234,56 @@ function afterRequest(server: express.Express, config: ServerConfig) {
|
|
|
217
234
|
}
|
|
218
235
|
}
|
|
219
236
|
|
|
220
|
-
function
|
|
237
|
+
function initializeSocketIO(io: SocketIOServer, app: express.Express) {
|
|
238
|
+
const logger = new Logger('SocketIOServer');
|
|
239
|
+
|
|
240
|
+
// Share session and passport middleware with Socket.IO
|
|
241
|
+
const wrapMiddleware = (middleware: any) => (socket: any, next: any) => middleware(socket.request, {}, next);
|
|
242
|
+
const sessionMiddleware = app.get('sessionMiddleware');
|
|
243
|
+
io.use(wrapMiddleware(sessionMiddleware));
|
|
244
|
+
io.use(wrapMiddleware(passport.initialize()));
|
|
245
|
+
io.use(wrapMiddleware(passport.session()));
|
|
246
|
+
|
|
247
|
+
// Use passport for authentication with Socket.IO
|
|
248
|
+
io.use((socket: ExtendedSocket, next) => {
|
|
249
|
+
if (socket.request.user) {
|
|
250
|
+
next();
|
|
251
|
+
} else {
|
|
252
|
+
next(new Error('Unauthorized'));
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Initialize Socket.IO event handlers
|
|
257
|
+
io.on('connection', (socket: ExtendedSocket) => {
|
|
258
|
+
const userInfo = `${socket.request.user} (${socket.id})`;
|
|
259
|
+
logger.info(`User connected: ${userInfo}`);
|
|
260
|
+
|
|
261
|
+
// Map this socket to the session id so it can be closed when the session is destroyed
|
|
262
|
+
const sessionId = socket.request.sessionID;
|
|
263
|
+
if (sessionId) {
|
|
264
|
+
socket.join(sessionId);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
socket.on('disconnect', (reason) => {
|
|
268
|
+
logger.info(`User disconnected: ${userInfo}. Reason: ${reason}`);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
socket.on('error', (error) => {
|
|
272
|
+
logger.error(`Socket error for user: ${userInfo}. Error:`, error);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
socket.conn.on('error', (error) => {
|
|
276
|
+
logger.error(`Socket connection error for user: ${userInfo}. Error:`, error);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Handle server-level errors
|
|
281
|
+
io.engine.on('connection_error', (err) => {
|
|
282
|
+
logger.error('Connection error:', err);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function start(server: HttpServer, config: ServerConfig) {
|
|
221
287
|
const port = config.port ? config.port : 3000;
|
|
222
288
|
server.listen(port, () => {
|
|
223
289
|
if (process.env.DEVELOPMENT) {
|