@things-factory/shell 6.2.34 → 6.2.44

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.
@@ -21,7 +21,18 @@ function getUrlFromContext(context, path = '') {
21
21
  }
22
22
  }
23
23
  let url = new url_1.URL(path, base);
24
- url.protocol = protocol || url.protocol;
24
+ const originalProtocol = context.headers['x-forwarded-proto'];
25
+ const originalHost = context.headers['x-forwarded-host'];
26
+ const originalPort = context.headers['x-forwarded-port'];
27
+ if (protocol || originalProtocol) {
28
+ url.protocol = protocol || originalProtocol;
29
+ }
30
+ if (originalHost) {
31
+ url.host = originalHost;
32
+ if (originalPort) {
33
+ url.port = originalPort;
34
+ }
35
+ }
25
36
  return url;
26
37
  }
27
38
  exports.getUrlFromContext = getUrlFromContext;
@@ -1 +1 @@
1
- {"version":3,"file":"get-domain.js","sourceRoot":"","sources":["../../server/utils/get-domain.ts"],"names":[],"mappings":";;;AAAA,6BAAyB;AAEzB,6CAA4C;AAC5C,iDAAmD;AAEnD,uDAAwD;AACxD,qDAAiD;AAEjD,MAAM,yBAAyB,GAAG,CAAC,CAAC,YAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;AAC3E,MAAM,QAAQ,GAAW,YAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;AAC/C,MAAM,KAAK,GAAG,YAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;AACrC,MAAM,eAAe,GAAG,YAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAA;AAE9D,SAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE;IAClD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAC9C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,EAAE,CAAA;IAEhC,IAAI,IAAI,GAAG,IAAI,CAAA;IAEf,IAAI,MAAM,KAA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OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAA;AAC1B,CAAC;AAdD,sDAcC;AAED,SAAgB,eAAe,CAAC,OAAO;IACrC,IAAI,yBAAyB,EAAE;QAC7B,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;QAChC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAEpC,IAAI,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAClE,OAAO,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,GAAG,CAAA;KAC3C;SAAM;QACL,OAAO,GAAG,CAAA;KACX;AACH,CAAC;AAVD,0CAUC","sourcesContent":["import { URL } from 'url'\n\nimport { config } from '@things-factory/env'\nimport { getPathInfo } from '@things-factory/utils'\n\nimport { getRepository } from '../initializers/database'\nimport { Domain } from '../service/domain/domain'\n\nconst useVirtualHostBasedDomain = !!config.get('useVirtualHostBasedDomain')\nconst protocol: string = config.get('protocol')\nconst fixed = config.get('subdomain')\nconst subdomainOffset = config.getNumber('subdomainOffset', 2)\n\nexport function getUrlFromContext(context, path = '') {\n const { method, href, host, header } = context\n const { referer } = header || {}\n\n var base = href\n\n if (method !== 'GET' && referer) {\n var { host: refererHost } = new URL(referer)\n if (refererHost === host) {\n base = referer\n }\n }\n\n let url: URL = new URL(path, base)\n url.protocol = protocol || url.protocol\n return url\n}\n\nfunction getSubdomainsFromHost(context: any) {\n const { request } = context\n var subdomains = request.headers.host.split('.').reverse()\n return subdomains.slice(subdomainOffset)\n}\n\nfunction getSubdomainFromPath(context: any) {\n var { path } = context\n\n var domain = getPathInfo(path || '')?.domain\n if (domain) {\n return domain\n }\n\n var {\n header: { referer }\n } = context\n\n if (referer) {\n var { pathname } = new URL(referer)\n return getPathInfo(pathname || '')?.domain\n }\n}\n\nfunction getSubdomainFromVhost(context: any) {\n const subdomain = (context.subdomains || getSubdomainsFromHost(context)).slice(-1)[0]\n\n return subdomain\n}\n\nfunction getSubdomainFromURL(context) {\n return fixed || (useVirtualHostBasedDomain ? getSubdomainFromVhost(context) : getSubdomainFromPath(context))\n}\n\nexport async function getDomainFromURL(context: any): Promise<Domain> {\n const { header } = context\n\n const subdomain = header['x-things-factory-domain'] || getSubdomainFromURL(context)\n\n if (subdomain) {\n return await getRepository(Domain).findOne({ where: { subdomain }, cache: true })\n }\n}\n\nexport function getCookieDomainFromHostname(hostname) {\n if (useVirtualHostBasedDomain) {\n return hostname.split('.').slice(-subdomainOffset).join('.')\n }\n}\n\nexport function getContextPath(subdomain) {\n return fixed || useVirtualHostBasedDomain ? '' : '/domain/' + subdomain\n}\n\nexport function getRedirectSubdomainPath(context, subdomain, redirectTo = '/') {\n if (fixed) {\n return redirectTo || '/'\n }\n\n var parsed = getUrlFromContext(context, redirectTo)\n var { hostname, pathname } = parsed\n\n if (useVirtualHostBasedDomain) {\n const splitHost = hostname.split('.').reverse()\n splitHost[subdomainOffset] = subdomain\n parsed.hostname = splitHost\n .reverse()\n .filter(a => a)\n .join('.')\n } else {\n const contextPath = `/domain/${subdomain}`\n const match = pathname.match(/^\\/domain\\/([^\\/]+)/)\n\n if (match) {\n parsed.pathname = pathname.replace(match[0], contextPath)\n } else {\n parsed.pathname = `${contextPath}${pathname}`\n }\n }\n\n return parsed.toString()\n}\n\nexport function findSubdomainFromPath(context, path) {\n if (fixed) {\n return fixed\n }\n\n var parsed = getUrlFromContext(context, path)\n var { hostname, pathname } = parsed\n\n if (useVirtualHostBasedDomain) {\n return hostname.split('.').reverse()[subdomainOffset]\n }\n\n const match = pathname.match(/^\\/domain\\/([^\\/]+)/)\n return match && match[1]\n}\n\nexport function getSiteRootPath(context) {\n if (useVirtualHostBasedDomain) {\n var { protocol, host } = context\n protocol = protocol.replace(':', '')\n\n let domainname = host.split('.').slice(-subdomainOffset).join('.')\n return protocol + '://' + domainname + '/'\n } else {\n return '/'\n }\n}\n"]}
1
+ {"version":3,"file":"get-domain.js","sourceRoot":"","sources":["../../server/utils/get-domain.ts"],"names":[],"mappings":";;;AAAA,6BAAyB;AAEzB,6CAA4C;AAC5C,iDAAmD;AAEnD,uDAAwD;AACxD,qDAAiD;AAEjD,MAAM,yBAAyB,GAAG,CAAC,CAAC,YAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;AAC3E,MAAM,QAAQ,GAAW,YAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;AAC/C,MAAM,KAAK,GAAG,YAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;AACrC,MAAM,eAAe,GAAG,YAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAA;AAE9D,SAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE;IAClD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAC9C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,EAAE,CAAA;IAEhC,IAAI,IAAI,GAAG,IAAI,CAAA;IAEf,IAAI,MAAM,KAAK,KAAK,IAAI,OAAO,EAAE;QAC/B,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,CAAA;QAC5C,IAAI,WAAW,KAAK,IAAI,EAAE;YACxB,IAAI,GAAG,OAAO,CAAA;SACf;KACF;IAED,IAAI,GAAG,GAAQ,IAAI,SAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAElC,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAA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AgB,eAAe,CAAC,OAAO;IACrC,IAAI,yBAAyB,EAAE;QAC7B,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;QAChC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAEpC,IAAI,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAClE,OAAO,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,GAAG,CAAA;KAC3C;SAAM;QACL,OAAO,GAAG,CAAA;KACX;AACH,CAAC;AAVD,0CAUC","sourcesContent":["import { URL } from 'url'\n\nimport { config } from '@things-factory/env'\nimport { getPathInfo } from '@things-factory/utils'\n\nimport { getRepository } from '../initializers/database'\nimport { Domain } from '../service/domain/domain'\n\nconst useVirtualHostBasedDomain = !!config.get('useVirtualHostBasedDomain')\nconst protocol: string = config.get('protocol')\nconst fixed = config.get('subdomain')\nconst subdomainOffset = config.getNumber('subdomainOffset', 2)\n\nexport function getUrlFromContext(context, path = '') {\n const { method, href, host, header } = context\n const { referer } = header || {}\n\n var base = href\n\n if (method !== 'GET' && referer) {\n var { host: refererHost } = new URL(referer)\n if (refererHost === host) {\n base = referer\n }\n }\n\n let url: URL = new URL(path, base)\n\n const originalProtocol = context.headers['x-forwarded-proto']\n const originalHost = context.headers['x-forwarded-host']\n const originalPort = context.headers['x-forwarded-port']\n\n if (protocol || originalProtocol) {\n url.protocol = protocol || originalProtocol\n }\n\n if (originalHost) {\n url.host = originalHost\n if (originalPort) {\n url.port = originalPort\n }\n }\n\n return url\n}\n\nfunction getSubdomainsFromHost(context: any) {\n const { request } = context\n var subdomains = request.headers.host.split('.').reverse()\n return subdomains.slice(subdomainOffset)\n}\n\nfunction getSubdomainFromPath(context: any) {\n var { path } = context\n\n var domain = getPathInfo(path || '')?.domain\n if (domain) {\n return domain\n }\n\n var {\n header: { referer }\n } = context\n\n if (referer) {\n var { pathname } = new URL(referer)\n return getPathInfo(pathname || '')?.domain\n }\n}\n\nfunction getSubdomainFromVhost(context: any) {\n const subdomain = (context.subdomains || getSubdomainsFromHost(context)).slice(-1)[0]\n\n return subdomain\n}\n\nfunction getSubdomainFromURL(context) {\n return fixed || (useVirtualHostBasedDomain ? getSubdomainFromVhost(context) : getSubdomainFromPath(context))\n}\n\nexport async function getDomainFromURL(context: any): Promise<Domain> {\n const { header } = context\n\n const subdomain = header['x-things-factory-domain'] || getSubdomainFromURL(context)\n\n if (subdomain) {\n return await getRepository(Domain).findOne({ where: { subdomain }, cache: true })\n }\n}\n\nexport function getCookieDomainFromHostname(hostname) {\n if (useVirtualHostBasedDomain) {\n return hostname.split('.').slice(-subdomainOffset).join('.')\n }\n}\n\nexport function getContextPath(subdomain) {\n return fixed || useVirtualHostBasedDomain ? '' : '/domain/' + subdomain\n}\n\nexport function getRedirectSubdomainPath(context, subdomain, redirectTo = '/') {\n if (fixed) {\n return redirectTo || '/'\n }\n\n var parsed = getUrlFromContext(context, redirectTo)\n var { hostname, pathname } = parsed\n\n if (useVirtualHostBasedDomain) {\n const splitHost = hostname.split('.').reverse()\n splitHost[subdomainOffset] = subdomain\n parsed.hostname = splitHost\n .reverse()\n .filter(a => a)\n .join('.')\n } else {\n const contextPath = `/domain/${subdomain}`\n const match = pathname.match(/^\\/domain\\/([^\\/]+)/)\n\n if (match) {\n parsed.pathname = pathname.replace(match[0], contextPath)\n } else {\n parsed.pathname = `${contextPath}${pathname}`\n }\n }\n\n return parsed.toString()\n}\n\nexport function findSubdomainFromPath(context, path) {\n if (fixed) {\n return fixed\n }\n\n var parsed = getUrlFromContext(context, path)\n var { hostname, pathname } = parsed\n\n if (useVirtualHostBasedDomain) {\n return hostname.split('.').reverse()[subdomainOffset]\n }\n\n const match = pathname.match(/^\\/domain\\/([^\\/]+)/)\n return match && match[1]\n}\n\nexport function getSiteRootPath(context) {\n if (useVirtualHostBasedDomain) {\n var { protocol, host } = context\n protocol = protocol.replace(':', '')\n\n let domainname = host.split('.').slice(-subdomainOffset).join('.')\n return protocol + '://' + domainname + '/'\n } else {\n return '/'\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/shell",
3
- "version": "6.2.34",
3
+ "version": "6.2.44",
4
4
  "description": "Core module for framework",
5
5
  "bin": {
6
6
  "things-factory": "bin/things-factory",
@@ -61,6 +61,7 @@
61
61
  "@operato/utils": "^1.0.1",
62
62
  "@things-factory/ejs-remote": "^6.2.33",
63
63
  "@things-factory/env": "^6.2.33",
64
+ "@things-factory/operato-license-checker": "^4.0.4",
64
65
  "@things-factory/styles": "^6.2.33",
65
66
  "@things-factory/utils": "^6.2.33",
66
67
  "@webcomponents/webcomponentsjs": "^2.6.0",
@@ -132,5 +133,5 @@
132
133
  "pg": "^8.7.3",
133
134
  "sqlite3": "^5.0.8"
134
135
  },
135
- "gitHead": "c1bf972f4b3b088638923bbf62badb572e1e6401"
136
+ "gitHead": "a2a1ebf823f6b1315e751b12a01372e9a867d7af"
136
137
  }
@@ -1,5 +1,6 @@
1
1
  import Router from 'koa-router'
2
2
 
3
+ import { getLicenseInfo } from '@things-factory/operato-license-checker'
3
4
  import { domainMiddleware } from '../middlewares/domain-middleware'
4
5
 
5
6
  var crawler = require('npm-license-crawler')
@@ -24,7 +25,12 @@ globalPublicRouter.get('/dependencies', async (context, next) => {
24
25
  await context.render('dependencies-view-graphviz', { model: dependencyGraph })
25
26
  })
26
27
 
27
- globalPublicRouter.get('/licenses', (context, next) => {
28
+ globalPublicRouter.get('/license-info', (context, next) => {
29
+ context.type = 'application/json'
30
+ context.body = getLicenseInfo()
31
+ })
32
+
33
+ globalPublicRouter.get('/opensource-licenses', (context, next) => {
28
34
  return new Promise(function (resolve, reject) {
29
35
  var options = {
30
36
  start: ['.'],
@@ -36,7 +42,7 @@ globalPublicRouter.get('/licenses', (context, next) => {
36
42
 
37
43
  crawler.dumpLicenses(options, function (error, res) {
38
44
  if (error) {
39
- console.error('get:/licenses', error)
45
+ console.error('get:/opensource-licenses', error)
40
46
  reject(error)
41
47
  } else {
42
48
  context.type = 'application/json'
@@ -47,6 +53,20 @@ globalPublicRouter.get('/licenses', (context, next) => {
47
53
  })
48
54
  })
49
55
 
56
+ globalPublicRouter.get('/request-info', context => {
57
+ const clientIP = context.headers['x-forwarded-for'] || context.ip
58
+ const protocol = context.headers['x-forwarded-proto'] || context.protocol
59
+ const host = context.headers['x-forwarded-host'] || context.host
60
+ const port = context.headers['x-forwarded-port'] || context.host.split(':')[1]
61
+
62
+ context.body = `
63
+ Client IP: ${clientIP}
64
+ Protocol: ${protocol}
65
+ Host: ${host}
66
+ Port: ${port}
67
+ `
68
+ })
69
+
50
70
  /* Paths starting with /public are assumed to use the koa-view renderer. */
51
71
  globalPublicRouter.get('/public/(.[^.]*)', async (context, next) => {
52
72
  const { path } = context
@@ -26,6 +26,7 @@ import http from 'http'
26
26
  import koaWebpack from '@hatiolab/koa-webpack'
27
27
  import cors from '@koa/cors'
28
28
  import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
29
+ import { initLicense, checkValidity } from '@things-factory/operato-license-checker'
29
30
 
30
31
  import { GraphqlLocalClient } from './graphql-local-client'
31
32
  import { databaseInitializer } from './initializers/database'
@@ -93,6 +94,8 @@ interface ICustomAppContext {
93
94
  ssoMiddlewares: any[]
94
95
  }
95
96
 
97
+ initLicense(config.get('licenseKey'))
98
+
96
99
  /* bootstrap */
97
100
  const bootstrap = async () => {
98
101
  await databaseInitializer()
@@ -259,6 +262,8 @@ const bootstrap = async () => {
259
262
  process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)
260
263
  process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)
261
264
 
265
+ app.use(checkValidity) /* Check the license after most of the context has been built */
266
+
262
267
  app
263
268
  .use(globalPublicRouter.routes())
264
269
  .use(globalPublicRouter.allowedMethods())
package/server/server.ts CHANGED
@@ -25,6 +25,7 @@ import http from 'http'
25
25
 
26
26
  import cors from '@koa/cors'
27
27
  import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
28
+ import { initLicense, checkValidity } from '@things-factory/operato-license-checker'
28
29
 
29
30
  import { GraphqlLocalClient } from './graphql-local-client'
30
31
  import { databaseInitializer } from './initializers/database'
@@ -68,6 +69,8 @@ const fileUploadOption = {
68
69
  maxFiles: fileUpload.maxFiles || 10
69
70
  }
70
71
 
72
+ initLicense(config.get('licenseKey'))
73
+
71
74
  /* bootstrap */
72
75
  const bootstrap = async () => {
73
76
  await databaseInitializer()
@@ -219,6 +222,8 @@ const bootstrap = async () => {
219
222
  process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)
220
223
  process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)
221
224
 
225
+ app.use(checkValidity) /* Check the license after most of the context has been built */
226
+
222
227
  app
223
228
  .use(globalPublicRouter.routes())
224
229
  .use(globalPublicRouter.allowedMethods())
@@ -25,7 +25,22 @@ export function getUrlFromContext(context, path = '') {
25
25
  }
26
26
 
27
27
  let url: URL = new URL(path, base)
28
- url.protocol = protocol || url.protocol
28
+
29
+ const originalProtocol = context.headers['x-forwarded-proto']
30
+ const originalHost = context.headers['x-forwarded-host']
31
+ const originalPort = context.headers['x-forwarded-port']
32
+
33
+ if (protocol || originalProtocol) {
34
+ url.protocol = protocol || originalProtocol
35
+ }
36
+
37
+ if (originalHost) {
38
+ url.host = originalHost
39
+ if (originalPort) {
40
+ url.port = originalPort
41
+ }
42
+ }
43
+
29
44
  return url
30
45
  }
31
46