@live-change/server 0.1.15 → 0.1.19

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/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
  }
@@ -35,6 +35,7 @@ class SsrServer {
35
35
  const staticPath = path.resolve(this.root, 'dist/client')
36
36
  this.express.use('/', expressStaticGzip(staticPath, {
37
37
  //enableBrotli: true,
38
+ index: false,
38
39
  customCompressions: [{
39
40
  encodingName: 'br',
40
41
  fileExtension: 'br'
@@ -64,7 +65,7 @@ class SsrServer {
64
65
  this.settings.sessionExpires ? new Date(Date.now() + this.settings.sessionExpires).toUTCString() : null
65
66
  if(credentials.sessionKey) {
66
67
  res.set({
67
- 'Set-Cookie': `sessionKey=${credentials.sessionKey}; Path=/`
68
+ 'Set-Cookie': `sessionKey=${credentials.sessionKey}; Path=/; HttpOnly`
68
69
  + (cookieExpireDate ? `; Expires=${cookieExpireDate}` : '')
69
70
  })
70
71
  }
@@ -91,18 +92,32 @@ class SsrServer {
91
92
 
92
93
  const version = this.version
93
94
 
94
- const html = await this.renderer.renderPage({ url, dao, clientIp, credentials, windowId, version })
95
+ let html
96
+ let error
95
97
 
96
- res.status(200)
97
- writeCredentials(res, credentials)
98
- res.set({
99
- 'Content-Type': 'text/html'
100
- })
101
- 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
+ }
102
118
  } catch (e) {
103
- this.renderer.fixStackTrace(e)
104
- console.error("RENDERING ERROR", e.stack)
105
- res.status(500).end(e.stack)
119
+ console.error("ERROR", e.stack || e)
120
+ res.status(500).end(e.stack || e)
106
121
  }
107
122
  })
108
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
@@ -8,7 +8,7 @@ async function setupApp(settings, env = process.env) {
8
8
  const app = require("@live-change/framework").app()
9
9
  app.instanceId = encodeNumber(hashCode(
10
10
  `app${process.pid}${require("os").hostname()} ${process.cwd()}/${process.argv.join(' ')}`))
11
- app.uidGenerator = uidGenerator(app.instanceId, 1)
11
+ app.uidGenerator = uidGenerator(app.instanceId, 1, settings.uidBorders)
12
12
  console.log("SETUP APP", settings)
13
13
  let dbServer
14
14
  if(settings.withDb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/server",
3
- "version": "0.1.15",
3
+ "version": "0.1.19",
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.4.82",
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>