@live-change/server 0.1.12 → 0.1.16
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/lib/Services.js +19 -10
- package/lib/SsrServer.js +19 -3
- package/lib/getIp.js +12 -0
- package/lib/serverDao.js +56 -0
- package/lib/setupApiServer.js +4 -6
- package/package.json +3 -2
package/lib/Services.js
CHANGED
|
@@ -34,17 +34,26 @@ class Services {
|
|
|
34
34
|
return this.config.services.find(s => s.name = serviceName)
|
|
35
35
|
}
|
|
36
36
|
async loadServices() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
app.config.services = this.config.services
|
|
38
|
+
app.config.plugins = this.config.plugins
|
|
39
|
+
if(this.config.plugins) {
|
|
40
|
+
for(const plugin of this.config.plugins) {
|
|
41
|
+
const entryFile = await this.getServiceEntryFile(plugin)
|
|
42
|
+
console.log("PLUGIN", plugin, 'ENTRY FILE', entryFile)
|
|
43
|
+
this.plugins.push(require(entryFile))
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
|
-
if(this.config.services)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
if(this.config.services) {
|
|
47
|
+
for(const service of this.config.services) {
|
|
48
|
+
const entryFile = await this.getServiceEntryFile(service)
|
|
49
|
+
console.log("SERVICE", service, 'ENTRY FILE', entryFile)
|
|
50
|
+
const definition = require(entryFile)
|
|
51
|
+
if(definition.name != service.name) {
|
|
52
|
+
console.error("SERVICE", service, "NAME", service.name, "MISMATCH", definition.name)
|
|
53
|
+
process.exit(1)
|
|
54
|
+
}
|
|
55
|
+
this.serviceDefinitions.push(definition)
|
|
56
|
+
}
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
/// TODO: load dependent services!!!
|
package/lib/SsrServer.js
CHANGED
|
@@ -2,10 +2,11 @@ const cookie = require('cookie')
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const serveStatic = require('serve-static')
|
|
4
4
|
const crypto = require('crypto')
|
|
5
|
+
const expressStaticGzip = require("express-static-gzip")
|
|
5
6
|
|
|
6
|
-
const serverDao = require('
|
|
7
|
+
const serverDao = require('./serverDao.js')
|
|
7
8
|
const { hashCode, encodeNumber, uidGenerator } = require('@live-change/uid')
|
|
8
|
-
const getIp = require('
|
|
9
|
+
const getIp = require('./getIp.js')
|
|
9
10
|
|
|
10
11
|
const Renderer = require('./Renderer.js')
|
|
11
12
|
|
|
@@ -32,7 +33,22 @@ class SsrServer {
|
|
|
32
33
|
this.express.use(this.renderer.vite.middlewares)
|
|
33
34
|
} else {
|
|
34
35
|
const staticPath = path.resolve(this.root, 'dist/client')
|
|
35
|
-
this.express.use(
|
|
36
|
+
this.express.use('/', expressStaticGzip(staticPath, {
|
|
37
|
+
//enableBrotli: true,
|
|
38
|
+
index: false,
|
|
39
|
+
customCompressions: [{
|
|
40
|
+
encodingName: 'br',
|
|
41
|
+
fileExtension: 'br'
|
|
42
|
+
},{
|
|
43
|
+
encodingName: 'gzip',
|
|
44
|
+
fileExtension: 'gz'
|
|
45
|
+
},{
|
|
46
|
+
encodingName: 'deflate',
|
|
47
|
+
fileExtension: 'zz'
|
|
48
|
+
}],
|
|
49
|
+
orderPreference: ['br', 'gzip', 'deflate']
|
|
50
|
+
}))
|
|
51
|
+
//this.express.use(serveStatic(staticPath, { index: false }))
|
|
36
52
|
}
|
|
37
53
|
|
|
38
54
|
await this.setupSsr()
|
package/lib/getIp.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function getIp(connection) {
|
|
2
|
+
let ip =
|
|
3
|
+
connection.headers['x-real-ip'] ||
|
|
4
|
+
connection.headers['x-forwarded-for'] ||
|
|
5
|
+
connection.remoteAddress ||
|
|
6
|
+
(connection.connection && connection.connection.remoteAddress)
|
|
7
|
+
ip = ip.split(',')[0]
|
|
8
|
+
ip = ip.split(':').slice(-1)[0] //in case the ip returned in a format: "::ffff:146.xxx.xxx.xxx"
|
|
9
|
+
return ip
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = getIp
|
package/lib/serverDao.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const { Dao } = require("@live-change/dao")
|
|
2
|
+
const DaoWebsocket = require("@live-change/dao-websocket")
|
|
3
|
+
|
|
4
|
+
function reactiveObservableListConstructor(reactive) {
|
|
5
|
+
class ReactiveObservableList extends Dao.ObservableList {
|
|
6
|
+
constructor(value, what, dispose) {
|
|
7
|
+
super(value, what, dispose, (data) => {
|
|
8
|
+
if(data && typeof data == 'object') {
|
|
9
|
+
const activated = reactive(data)
|
|
10
|
+
return activated
|
|
11
|
+
}
|
|
12
|
+
return data
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return ReactiveObservableList
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function serverDao(credentials, ip, settings) {
|
|
20
|
+
const serverHost = settings.remoteUrl || process.env.API_SERVER || "localhost:" + (process.env.API_PORT || 8002)
|
|
21
|
+
const wsServer = `ws://${serverHost}/api/ws`
|
|
22
|
+
|
|
23
|
+
return new Dao(credentials, {
|
|
24
|
+
remoteUrl: wsServer,
|
|
25
|
+
protocols: {
|
|
26
|
+
'ws': DaoWebsocket.client
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
...settings,
|
|
30
|
+
|
|
31
|
+
connectionSettings: {
|
|
32
|
+
headers: {
|
|
33
|
+
'X-real-ip': ip,
|
|
34
|
+
'X-forwarded-for': ip
|
|
35
|
+
},
|
|
36
|
+
queueRequestsWhenDisconnected: true,
|
|
37
|
+
requestSendTimeout: 2300,
|
|
38
|
+
requestTimeout: 10000,
|
|
39
|
+
queueActiveRequestsOnDisconnect: false,
|
|
40
|
+
autoReconnectDelay: 200,
|
|
41
|
+
logLevel: 1,
|
|
42
|
+
/*connectionMonitorFactory: (connection) =>
|
|
43
|
+
new ReactiveDao.ConnectionMonitorPinger(connection, {
|
|
44
|
+
pingInterval: 50,
|
|
45
|
+
pongInterval: 200
|
|
46
|
+
})*/
|
|
47
|
+
...(settings && settings.connectionSettings)
|
|
48
|
+
},
|
|
49
|
+
defaultRoute: {
|
|
50
|
+
type: "remote",
|
|
51
|
+
generator: settings.reactive ? reactiveObservableListConstructor(settings.reactive) : Dao.ObservableList
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = serverDao
|
package/lib/setupApiServer.js
CHANGED
|
@@ -4,7 +4,7 @@ const app = require("@live-change/framework").app()
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
async function setupApiServer(settings) {
|
|
7
|
-
const { services: config, withServices, updateServices
|
|
7
|
+
const { services: config, withServices, updateServices } = settings
|
|
8
8
|
|
|
9
9
|
const services = new Services(config)
|
|
10
10
|
|
|
@@ -41,13 +41,11 @@ async function setupApiServer(settings) {
|
|
|
41
41
|
},
|
|
42
42
|
shareDefinition: true,
|
|
43
43
|
logErrors: true,
|
|
44
|
-
createSessionOnUpdate: true
|
|
44
|
+
createSessionOnUpdate: true /// deprecated - moved to session-service settings
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const apiServer =
|
|
48
|
-
|
|
49
|
-
: await app.createApiServer(apiServerConfig)
|
|
50
|
-
|
|
47
|
+
const apiServer = await app.createLiveApiServer(apiServerConfig)
|
|
48
|
+
|
|
51
49
|
apiServer.services = services
|
|
52
50
|
|
|
53
51
|
return apiServer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Live Change Framework - server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"serialize-javascript": "^5.0.1",
|
|
36
36
|
"sockjs": "^0.3.21",
|
|
37
37
|
"websocket": "^1.0.34",
|
|
38
|
-
"yargs": "^17.0.1"
|
|
38
|
+
"yargs": "^17.0.1",
|
|
39
|
+
"express-static-gzip": "2.1.1"
|
|
39
40
|
}
|
|
40
41
|
}
|