@live-change/server 0.1.16 → 0.1.20

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/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/server.iml" filepath="$PROJECT_DIR$/server.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
package/lib/Services.js CHANGED
@@ -4,6 +4,8 @@ const path = require('path')
4
4
  const resolve = require('util').promisify(require('resolve'))
5
5
  const app = require("@live-change/framework").app()
6
6
 
7
+ const debug = require('debug')('framework')
8
+
7
9
  class Services {
8
10
  constructor(configPath) {
9
11
  if(!configPath) throw new Error("services config parameter is required")
@@ -18,12 +20,12 @@ class Services {
18
20
 
19
21
  async resolve(file) {
20
22
  const path = await resolve(file, { basedir: this.servicesDir })
21
- console.log("PATH RESOLVE", file, "IN", this.servicesDir, "=>", path)
23
+ debug("PATH RESOLVE", file, "IN", this.servicesDir, "=>", path)
22
24
  return path
23
25
  }
24
26
  async getServiceEntryFile(config) {
25
27
  const path = await resolve(config.path, { basedir: this.servicesDir })
26
- console.log("PATH RESOLVE", config.path, "IN", this.servicesDir, "=>", path)
28
+ debug("PATH RESOLVE", config.path, "IN", this.servicesDir, "=>", path)
27
29
  return path
28
30
  }
29
31
 
@@ -39,14 +41,14 @@ class Services {
39
41
  if(this.config.plugins) {
40
42
  for(const plugin of this.config.plugins) {
41
43
  const entryFile = await this.getServiceEntryFile(plugin)
42
- console.log("PLUGIN", plugin, 'ENTRY FILE', entryFile)
44
+ debug("PLUGIN", plugin, 'ENTRY FILE', entryFile)
43
45
  this.plugins.push(require(entryFile))
44
46
  }
45
47
  }
46
48
  if(this.config.services) {
47
49
  for(const service of this.config.services) {
48
50
  const entryFile = await this.getServiceEntryFile(service)
49
- console.log("SERVICE", service, 'ENTRY FILE', entryFile)
51
+ debug("SERVICE", service, 'ENTRY FILE', entryFile)
50
52
  const definition = require(entryFile)
51
53
  if(definition.name != service.name) {
52
54
  console.error("SERVICE", service, "NAME", service.name, "MISMATCH", definition.name)
package/lib/SsrServer.js CHANGED
@@ -21,7 +21,7 @@ class SsrServer {
21
21
 
22
22
  this.instanceId = encodeNumber(hashCode(
23
23
  `ssr${process.pid}${require("os").hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
24
- this.uidGenerator = uidGenerator(this.instanceId, 1)
24
+ this.uidGenerator = uidGenerator(this.instanceId, 1, this.settings.uidBorders)
25
25
 
26
26
  this.root = this.settings.root || process.cwd()
27
27
  }
@@ -65,7 +65,7 @@ class SsrServer {
65
65
  this.settings.sessionExpires ? new Date(Date.now() + this.settings.sessionExpires).toUTCString() : null
66
66
  if(credentials.sessionKey) {
67
67
  res.set({
68
- 'Set-Cookie': `sessionKey=${credentials.sessionKey}; Path=/`
68
+ 'Set-Cookie': `sessionKey=${credentials.sessionKey}; Path=/; HttpOnly`
69
69
  + (cookieExpireDate ? `; Expires=${cookieExpireDate}` : '')
70
70
  })
71
71
  }
@@ -92,18 +92,32 @@ class SsrServer {
92
92
 
93
93
  const version = this.version
94
94
 
95
- const html = await this.renderer.renderPage({ url, dao, clientIp, credentials, windowId, version })
95
+ let html
96
+ let error
96
97
 
97
- res.status(200)
98
- writeCredentials(res, credentials)
99
- res.set({
100
- 'Content-Type': 'text/html'
101
- })
102
- res.end(html)
98
+ for(let retry = 0; retry < 3; retry ++) {
99
+ try {
100
+ html = await this.renderer.renderPage({ url, dao, clientIp, credentials, windowId, version })
101
+ break
102
+ } catch(e) {
103
+ error = e
104
+ }
105
+ }
106
+ if(html) {
107
+ res.status(200)
108
+ writeCredentials(res, credentials)
109
+ res.set({
110
+ 'Content-Type': 'text/html'
111
+ })
112
+ res.end(html)
113
+ } else {
114
+ if(error.stack) this.renderer.fixStackTrace(error)
115
+ console.error("RENDERING ERROR", error.stack || error)
116
+ res.status(500).end(error.stack || error)
117
+ }
103
118
  } catch (e) {
104
- this.renderer.fixStackTrace(e)
105
- console.error("RENDERING ERROR", e.stack)
106
- res.status(500).end(e.stack)
119
+ console.error("ERROR", e.stack || e)
120
+ res.status(500).end(e.stack || e)
107
121
  }
108
122
  })
109
123
  }
package/lib/TestServer.js CHANGED
@@ -27,7 +27,7 @@ class TestServer {
27
27
 
28
28
  app.instanceId = encodeNumber(hashCode(
29
29
  `app${process.pid}${require("os").hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
30
- app.uidGenerator = uidGenerator(app.instanceId, 1)
30
+ app.uidGenerator = uidGenerator(app.instanceId, 1, '[]')
31
31
  this.dbServer = await setupDbServer({ dbBackend: 'mem' })
32
32
  const loopbackDao = await createLoopbackDao('local', () => this.dbServer.createDao('local'))
33
33
  app.dao = loopbackDao
@@ -60,8 +60,9 @@ class TestServer {
60
60
 
61
61
  await new Promise((resolve, reject) => {
62
62
  this.httpServer = this.expressServer.listen(this.config.port || 0, () => {
63
- this.port = this.expressServer.address().port,
63
+ this.port = this.expressServer.address().port
64
64
  this.url = `http://localhost:${this.expressServer.address().port}`
65
+ process.env.SSR_PORT = this.port
65
66
  resolve()
66
67
  })
67
68
  })
@@ -1,4 +1,6 @@
1
+ const cookie = require("cookie")
1
2
  const Dao = require("@live-change/dao")
3
+ const { connection } = require("websocket")
2
4
  const Services = require('../lib/Services.js')
3
5
  const app = require("@live-change/framework").app()
4
6
 
@@ -41,7 +43,14 @@ async function setupApiServer(settings) {
41
43
  },
42
44
  shareDefinition: true,
43
45
  logErrors: true,
44
- createSessionOnUpdate: true /// deprecated - moved to session-service settings
46
+ createSessionOnUpdate: true, /// deprecated - moved to session-service settings
47
+ fastAuth: settings.fastAuth /* && ((connection) => {
48
+ const cookies = cookie.parse(connection.headers.cookie || '')
49
+ return {
50
+ sesionId: cookies.sessionId,
51
+ sessionKey: cookies.sessionKey
52
+ }
53
+ }) */
45
54
  }
46
55
 
47
56
  const apiServer = await app.createLiveApiServer(apiServerConfig)
@@ -1,7 +1,10 @@
1
- const sockjs = require('sockjs')
1
+ const sockjs = require('@live-change/sockjs')
2
2
 
3
3
  function setupApiSockJs(httpServer, apiServer) {
4
- const sockJsServer = sockjs.createServer({})
4
+ const sockJsServer = sockjs.createServer({
5
+ prefix: '/api/sockjs',
6
+ transports: [ 'websocket', 'websocket-raw', 'xhr-polling', 'xhr-streaming' ]
7
+ })
5
8
  sockJsServer.on('connection', function (conn) {
6
9
  if(!conn) {
7
10
  console.error("NULL SOCKJS connection")
@@ -10,7 +13,7 @@ function setupApiSockJs(httpServer, apiServer) {
10
13
  console.log("SOCKJS connection")
11
14
  apiServer.handleConnection(conn)
12
15
  })
13
- sockJsServer.installHandlers(httpServer, { prefix: '/api/sockjs' })
16
+ sockJsServer.attach(httpServer)
14
17
 
15
18
  return sockJsServer
16
19
  }
package/lib/setupApp.js CHANGED
@@ -4,12 +4,14 @@ const setupDbServer = require('./setupDbServer.js')
4
4
  const setupDbClient = require('./setupDbClient.js')
5
5
  const createLoopbackDao = require('./createLoopbackDao.js')
6
6
 
7
+ const debug = require('debug')('server:app')
8
+
7
9
  async function setupApp(settings, env = process.env) {
8
10
  const app = require("@live-change/framework").app()
9
11
  app.instanceId = encodeNumber(hashCode(
10
12
  `app${process.pid}${require("os").hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
11
- app.uidGenerator = uidGenerator(app.instanceId, 1)
12
- console.log("SETUP APP", settings)
13
+ app.uidGenerator = uidGenerator(app.instanceId, 1, settings.uidBorders)
14
+ debug("SETUP APP", settings)
13
15
  let dbServer
14
16
  if(settings.withDb) {
15
17
  dbServer = await setupDbServer(settings)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/server",
3
- "version": "0.1.16",
3
+ "version": "0.1.20",
4
4
  "description": "Live Change Framework - server",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,21 +21,21 @@
21
21
  },
22
22
  "homepage": "https://github.com/live-change/server",
23
23
  "dependencies": {
24
- "@live-change/dao": "^0.3.3",
25
- "@live-change/dao-sockjs": "^0.2.0",
26
- "@live-change/db-server": "^0.4.80",
27
- "@live-change/framework": "^0.5.0",
28
- "@live-change/vue3-ssr": "^0.1.0",
29
- "@live-change/uid": "^0.1.3",
30
- "http-proxy-middleware": "2.0.0",
31
- "dotenv": "^9.0.2",
24
+ "@live-change/dao": "^0.3.12",
25
+ "@live-change/dao-sockjs": "^0.2.1",
26
+ "@live-change/db-server": "^0.5.3",
27
+ "@live-change/framework": "^0.5.10",
28
+ "@live-change/vue3-ssr": "^0.1.7",
29
+ "@live-change/uid": "^0.1.4",
30
+ "http-proxy-middleware": "2.0.1",
31
+ "dotenv": "^10.0.0",
32
32
  "express": "^4.17.1",
33
33
  "resolve": "^1.20.0",
34
34
  "segfault-handler": "^1.3.0",
35
- "serialize-javascript": "^5.0.1",
36
- "sockjs": "^0.3.21",
35
+ "serialize-javascript": "^6.0.0",
36
+ "@live-change/sockjs": "^0.4.0-rc.1",
37
37
  "websocket": "^1.0.34",
38
- "yargs": "^17.0.1",
38
+ "yargs": "^17.3.0",
39
39
  "express-static-gzip": "2.1.1"
40
40
  }
41
41
  }
package/server.iml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>