@things-factory/shell 8.0.2 → 8.0.8
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/config/config.development.js +1 -1
- package/config/config.production.js +1 -14
- package/dist-server/middlewares/domain-middleware.js +3 -3
- package/dist-server/middlewares/domain-middleware.js.map +1 -1
- package/dist-server/service/domain/domain-query.d.ts +4 -3
- package/dist-server/service/domain/domain-query.js +27 -15
- package/dist-server/service/domain/domain-query.js.map +1 -1
- package/dist-server/service/domain/domain-types.d.ts +2 -0
- package/dist-server/service/domain/domain-types.js +8 -0
- package/dist-server/service/domain/domain-types.js.map +1 -1
- package/dist-server/service/domain/domain.js +4 -38
- package/dist-server/service/domain/domain.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/get-domain.d.ts +3 -10
- package/dist-server/utils/get-domain.js +52 -71
- package/dist-server/utils/get-domain.js.map +1 -1
- package/dist-server/utils/get-query-builder-from-list-params.d.ts +2 -2
- package/dist-server/utils/get-query-builder-from-list-params.js +5 -5
- package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
- package/package.json +4 -4
- package/server/middlewares/domain-middleware.ts +3 -3
- package/server/service/domain/domain-query.ts +11 -4
- package/server/service/domain/domain-types.ts +6 -0
- package/server/service/domain/domain.ts +4 -39
- package/server/utils/get-domain.ts +60 -73
- package/server/utils/get-query-builder-from-list-params.ts +3 -3
@@ -1,3 +1,4 @@
|
|
1
|
+
import { In } from 'typeorm'
|
1
2
|
import { URL } from 'url'
|
2
3
|
|
3
4
|
import { config } from '@things-factory/env'
|
@@ -6,10 +7,9 @@ import { getPathInfo } from '@things-factory/utils'
|
|
6
7
|
import { getRepository } from '../initializers/database'
|
7
8
|
import { Domain } from '../service/domain/domain'
|
8
9
|
|
9
|
-
const useVirtualHostBasedDomain = !!config.get('useVirtualHostBasedDomain')
|
10
10
|
const protocol: string = config.get('protocol')
|
11
11
|
const fixed = config.get('subdomain')
|
12
|
-
const
|
12
|
+
const domainTypes = config.get('domainTypes') || ['domain']
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Creates a URL based on the given context and path.
|
@@ -51,18 +51,6 @@ export function getUrlFromContext(context, path = '') {
|
|
51
51
|
return url
|
52
52
|
}
|
53
53
|
|
54
|
-
/**
|
55
|
-
* Extracts subdomains from the Host header.
|
56
|
-
*
|
57
|
-
* @param context {Object} An object containing the current request context information.
|
58
|
-
* @returns {string[]} An array of extracted subdomains.
|
59
|
-
*/
|
60
|
-
function getSubdomainsFromHost(context: any) {
|
61
|
-
const { request } = context
|
62
|
-
var subdomains = request.headers.host.split('.').reverse()
|
63
|
-
return subdomains.slice(subdomainOffset)
|
64
|
-
}
|
65
|
-
|
66
54
|
/**
|
67
55
|
* Extracts a subdomain from the path.
|
68
56
|
*
|
@@ -72,9 +60,9 @@ function getSubdomainsFromHost(context: any) {
|
|
72
60
|
function getSubdomainFromPath(context: any) {
|
73
61
|
var { path } = context
|
74
62
|
|
75
|
-
var
|
76
|
-
if (
|
77
|
-
return
|
63
|
+
var subdomain = getPathInfo(path || '', domainTypes)?.subdomain
|
64
|
+
if (subdomain) {
|
65
|
+
return subdomain
|
78
66
|
}
|
79
67
|
|
80
68
|
var {
|
@@ -83,20 +71,32 @@ function getSubdomainFromPath(context: any) {
|
|
83
71
|
|
84
72
|
if (referer) {
|
85
73
|
var { pathname } = new URL(referer)
|
86
|
-
return getPathInfo(pathname || '')?.
|
74
|
+
return getPathInfo(pathname || '', domainTypes)?.subdomain
|
87
75
|
}
|
88
76
|
}
|
89
77
|
|
90
78
|
/**
|
91
|
-
* Extracts
|
79
|
+
* Extracts the subdomain type from the given context's path or referer header.
|
92
80
|
*
|
93
|
-
* @param context
|
94
|
-
* @returns
|
81
|
+
* @param context - The context object containing path and header information.
|
82
|
+
* @returns The subdomain type if found, otherwise undefined.
|
95
83
|
*/
|
96
|
-
function
|
97
|
-
|
84
|
+
function getSubdomainTypeFromPath(context: any) {
|
85
|
+
var { path } = context
|
98
86
|
|
99
|
-
|
87
|
+
var prefix = getPathInfo(path || '', domainTypes)?.prefix
|
88
|
+
if (prefix) {
|
89
|
+
return prefix
|
90
|
+
}
|
91
|
+
|
92
|
+
var {
|
93
|
+
header: { referer }
|
94
|
+
} = context
|
95
|
+
|
96
|
+
if (referer) {
|
97
|
+
var { pathname } = new URL(referer)
|
98
|
+
return getPathInfo(pathname || '', domainTypes)?.prefix
|
99
|
+
}
|
100
100
|
}
|
101
101
|
|
102
102
|
/**
|
@@ -106,7 +106,11 @@ function getSubdomainFromVhost(context: any) {
|
|
106
106
|
* @returns {string} The extracted subdomain.
|
107
107
|
*/
|
108
108
|
function getSubdomainFromURL(context) {
|
109
|
-
return fixed ||
|
109
|
+
return fixed || getSubdomainFromPath(context)
|
110
|
+
}
|
111
|
+
|
112
|
+
function getSubdomainTypeFromURL(context) {
|
113
|
+
return fixed ? '' : getSubdomainTypeFromPath(context)
|
110
114
|
}
|
111
115
|
|
112
116
|
/**
|
@@ -119,21 +123,21 @@ export async function getDomainFromURL(context: any): Promise<Domain> {
|
|
119
123
|
const { header } = context
|
120
124
|
|
121
125
|
const subdomain = header['x-things-factory-domain'] || getSubdomainFromURL(context)
|
126
|
+
const extType = header['x-things-factory-type'] || getSubdomainTypeFromURL(context)
|
122
127
|
|
123
128
|
if (subdomain) {
|
124
|
-
return await getRepository(Domain).findOne({
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
return hostname.split('.').slice(-subdomainOffset).join('.')
|
129
|
+
return await getRepository(Domain).findOne({
|
130
|
+
where:
|
131
|
+
fixed || extType == 'domain' || !extType
|
132
|
+
? {
|
133
|
+
subdomain
|
134
|
+
}
|
135
|
+
: {
|
136
|
+
subdomain,
|
137
|
+
extType
|
138
|
+
},
|
139
|
+
cache: true
|
140
|
+
})
|
137
141
|
}
|
138
142
|
}
|
139
143
|
|
@@ -143,42 +147,37 @@ export function getCookieDomainFromHostname(hostname) {
|
|
143
147
|
* @param subdomain {string} The subdomain.
|
144
148
|
* @returns {string} The generated context path.
|
145
149
|
*/
|
146
|
-
export function getContextPath(
|
147
|
-
|
150
|
+
export function getContextPath(domain: Domain) {
|
151
|
+
const type = domain?.extType || 'domain'
|
152
|
+
return fixed || !domain ? '' : `${type}/${domain?.subdomain}/`
|
148
153
|
}
|
149
154
|
|
150
155
|
/**
|
151
156
|
* Generates a redirection path considering the subdomain.
|
152
157
|
*
|
153
158
|
* @param context {Object} An object containing the current request context information.
|
154
|
-
* @param subdomain {
|
159
|
+
* @param subdomain {Domain} The target domain.
|
155
160
|
* @param redirectTo {string} The path to redirect to (optional).
|
156
161
|
* @returns {string} The generated redirection path.
|
157
162
|
*/
|
158
|
-
export function getRedirectSubdomainPath(context,
|
159
|
-
if (fixed) {
|
163
|
+
export function getRedirectSubdomainPath(context, domain: Partial<Domain>, redirectTo: string = '/') {
|
164
|
+
if (fixed || !domain) {
|
160
165
|
return redirectTo || '/'
|
161
166
|
}
|
162
167
|
|
168
|
+
const type = domain.extType || 'domain'
|
169
|
+
const subdomain = domain.subdomain || fixed
|
170
|
+
|
163
171
|
var parsed = getUrlFromContext(context, redirectTo)
|
164
172
|
var { hostname, pathname } = parsed
|
165
173
|
|
166
|
-
|
167
|
-
|
168
|
-
splitHost[subdomainOffset] = subdomain
|
169
|
-
parsed.hostname = splitHost
|
170
|
-
.reverse()
|
171
|
-
.filter(a => a)
|
172
|
-
.join('.')
|
173
|
-
} else {
|
174
|
-
const contextPath = `/domain/${subdomain}`
|
175
|
-
const match = pathname.match(/^\/domain\/([^\/]+)/)
|
174
|
+
const contextPath = `/${type}/${subdomain}`
|
175
|
+
const match = pathname.match(new RegExp(`^/${type}/([^\/]+)`))
|
176
176
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
}
|
177
|
+
if (match) {
|
178
|
+
parsed.pathname = pathname.replace(match[0], contextPath)
|
179
|
+
} else {
|
180
|
+
parsed.pathname = `${contextPath}${pathname}`
|
182
181
|
}
|
183
182
|
|
184
183
|
return parsed.toString()
|
@@ -197,13 +196,9 @@ export function findSubdomainFromPath(context, path) {
|
|
197
196
|
}
|
198
197
|
|
199
198
|
var parsed = getUrlFromContext(context, path)
|
200
|
-
var {
|
199
|
+
var { pathname } = parsed
|
201
200
|
|
202
|
-
|
203
|
-
return hostname.split('.').reverse()[subdomainOffset]
|
204
|
-
}
|
205
|
-
|
206
|
-
const match = pathname.match(/^\/domain\/([^\/]+)/)
|
201
|
+
const match = pathname.match(new RegExp(`^/${getSubdomainTypeFromURL(context)}/([^\/]+)`))
|
207
202
|
return match && match[1]
|
208
203
|
}
|
209
204
|
|
@@ -214,13 +209,5 @@ export function findSubdomainFromPath(context, path) {
|
|
214
209
|
* @returns {string} The generated site root path.
|
215
210
|
*/
|
216
211
|
export function getSiteRootPath(context) {
|
217
|
-
|
218
|
-
var { protocol, host } = context
|
219
|
-
protocol = protocol.replace(':', '')
|
220
|
-
|
221
|
-
let domainname = host.split('.').slice(-subdomainOffset).join('.')
|
222
|
-
return protocol + '://' + domainname + '/'
|
223
|
-
} else {
|
224
|
-
return '/'
|
225
|
-
}
|
212
|
+
return '/'
|
226
213
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Brackets, EntityMetadata, Repository, SelectQueryBuilder, WhereExpressionBuilder } from 'typeorm'
|
2
|
-
import { RelationMetadata } from 'typeorm/metadata/RelationMetadata'
|
3
|
-
import { Filter, Sorting, Pagination, ListParam, InheritedValueType } from '../service/common-types/list-param'
|
4
|
-
import { Domain } from '../service/domain/domain'
|
2
|
+
import { RelationMetadata } from 'typeorm/metadata/RelationMetadata.js'
|
3
|
+
import { Filter, Sorting, Pagination, ListParam, InheritedValueType } from '../service/common-types/list-param.js'
|
4
|
+
import { Domain } from '../service/domain/domain.js'
|
5
5
|
|
6
6
|
/**
|
7
7
|
* Creates a TypeORM SelectQueryBuilder based on the provided parameters.
|