@warren-bank/hls-proxy 3.2.3 → 3.2.4

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.
@@ -0,0 +1,32 @@
1
+ const get_full_req_url = function(req) {
2
+ return req.originalUrl || req.url
3
+ }
4
+
5
+ const has_req_param = function(req, key) {
6
+ return (req.params && (typeof req.params === 'object') && req.params[key])
7
+ }
8
+
9
+ const get_proxy_req_url = function(req) {
10
+ const key = "0"
11
+ return has_req_param(req, key)
12
+ ? `/${req.params[key]}`
13
+ : req.url
14
+ }
15
+
16
+ const get_base_req_url = function(req) {
17
+ let base_url = ''
18
+ const key = "0"
19
+
20
+ if (req.path && has_req_param(req, key)) {
21
+ base_url = req.baseUrl || ''
22
+ base_url += req.path.substring(0, (req.path.length - req.params[key].length - 1))
23
+ }
24
+
25
+ return base_url
26
+ }
27
+
28
+ module.exports = {
29
+ get_full_req_url,
30
+ get_proxy_req_url,
31
+ get_base_req_url
32
+ }
@@ -1,4 +1,5 @@
1
1
  const parse_url = require('@warren-bank/url').parse
2
+ const expressjs = require('./expressjs_utils')
2
3
 
3
4
  const regexs = {
4
5
  req_url: new RegExp('^(.*?)/([a-zA-Z0-9\\+/=%]+)(?:[\\._]([^/\\?#]*))?(?:[\\?#].*)?$'),
@@ -20,10 +21,10 @@ const parse_req_url = function(params, req) {
20
21
 
21
22
  const result = {redirected_base_url: '', url_type: '', url: '', referer_url: ''}
22
23
 
23
- const matches = regexs.req_url.exec(req.url)
24
+ const matches = regexs.req_url.exec( expressjs.get_proxy_req_url(req) )
24
25
 
25
26
  if (matches) {
26
- result.redirected_base_url = `${ is_secure ? 'https' : 'http' }://${host || req.headers.host}${matches[1] || ''}`
27
+ result.redirected_base_url = `${ is_secure ? 'https' : 'http' }://${host || req.headers.host}${expressjs.get_base_req_url(req) || matches[1] || ''}`
27
28
 
28
29
  if (matches[3])
29
30
  result.url_type = matches[3].toLowerCase().trim()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@warren-bank/hls-proxy",
3
3
  "description": "Node.js server to proxy HLS video streams",
4
- "version": "3.2.3",
4
+ "version": "3.2.4",
5
5
  "scripts": {
6
6
  "start": "node hls-proxy/bin/hlsd.js",
7
7
  "sudo": "sudo node hls-proxy/bin/hlsd.js"