@live-change/server 0.7.34 → 0.7.35

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/SsrServer.js CHANGED
@@ -10,6 +10,8 @@ const getIp = require('./getIp.js')
10
10
 
11
11
  const Renderer = require('./Renderer.js')
12
12
 
13
+ const { fbRedirect } = require('./fbRedirect.js')
14
+
13
15
  class SsrServer {
14
16
  constructor(express, manifest, settings) {
15
17
  this.manifest = manifest
@@ -99,6 +101,7 @@ class SsrServer {
99
101
  this.renderer.renderSitemap({ dao, clientIp }, res)
100
102
  })
101
103
  this.express.use('*', async (req, res) => {
104
+ if(fbRedirect(req, res)) return
102
105
  if(this.settings.spa) {
103
106
  if(this.settings.dev) {
104
107
  res.sendFile(path.resolve(this.root, 'index.html'))
@@ -0,0 +1,37 @@
1
+ function isAppSpecificUserAgent(userAgent) {
2
+ if(!userAgent) return false
3
+ const appSpecificUserAgents = ["FBAN", "FBAV"]
4
+ for (let i = 0; i <= appSpecificUserAgents.length; i++) {
5
+ if (userAgent.indexOf(appSpecificUserAgents[i]) > -1) return true
6
+ }
7
+ }
8
+ function isIOs(userAgent) {
9
+ if(!userAgent) return false
10
+ const iOsUserAgents = ["iPad", "iPhone", "iPod"]
11
+ for (let i = 0; i <= iOsUserAgents.length; i++) {
12
+ if (userAgent.indexOf(iOsUserAgents[i]) > -1) return true
13
+ }
14
+ }
15
+
16
+ function fbRedirect(req, res) {
17
+ const userAgent = req.get('user-agent')
18
+ if(isAppSpecificUserAgent(userAgent)) {
19
+ const redirectUrl = (process.env.BASE_HREF || `${req.header('host')}`) + req.url
20
+ console.log("REDIRECTING FB MESSENGER TO", redirectUrl)
21
+ if(!isIOs(userAgent)) {
22
+ res.redirect(302, "googlechrome://navigate?url=https://"+redirectUrl)
23
+ res.end("facebook messanger internal browser is not supported")
24
+ return true
25
+ } else {
26
+ console.log("FACEBOOK MESSENGER ON iOS DOES NOT ALLOW REDIRECT TO BROWSER")
27
+ /*res.redirect(302, "googlechromes://"+redirectUrl)
28
+ res.end("facebook messanger internal browser is not supported")*/
29
+ }
30
+ }
31
+ }
32
+
33
+ module.exports = {
34
+ isAppSpecificUserAgent,
35
+ isIOs,
36
+ fbRedirect
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/server",
3
- "version": "0.7.34",
3
+ "version": "0.7.35",
4
4
  "description": "Live Change Framework - server",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,9 +24,9 @@
24
24
  "@live-change/dao": "0.5.22",
25
25
  "@live-change/dao-sockjs": "0.5.22",
26
26
  "@live-change/db-server": "0.6.23",
27
- "@live-change/framework": "^0.7.34",
27
+ "@live-change/framework": "^0.7.35",
28
28
  "@live-change/sockjs": "0.4.1",
29
- "@live-change/uid": "^0.7.34",
29
+ "@live-change/uid": "^0.7.35",
30
30
  "dotenv": "^16.0.3",
31
31
  "express": "^4.18.2",
32
32
  "express-static-gzip": "2.1.7",
@@ -38,5 +38,5 @@
38
38
  "websocket": "^1.0.34",
39
39
  "yargs": "^17.5.1"
40
40
  },
41
- "gitHead": "730c14caf86069665193ce157b2663358abef342"
41
+ "gitHead": "11313d136ef6bc6770050671a61721c2fa7586f9"
42
42
  }