web_plsql 0.3.2 → 0.5.0

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.
Files changed (44) hide show
  1. package/.editorconfig +8 -8
  2. package/.eslintignore +3 -3
  3. package/.eslintrc.js +347 -273
  4. package/CHANGELOG.md +127 -106
  5. package/LICENSE +21 -21
  6. package/README.md +165 -164
  7. package/examples/apex.js +70 -70
  8. package/examples/credentials.js +22 -22
  9. package/examples/oracledb_example.js +30 -30
  10. package/examples/sample.js +101 -84
  11. package/examples/sql/doc_table.sql +13 -13
  12. package/examples/sql/install.sql +31 -31
  13. package/examples/sql/sample.pkb +223 -223
  14. package/examples/sql/sample.pks +24 -24
  15. package/examples/sql/uninstall.sql +5 -5
  16. package/examples/static/sample.css +25 -25
  17. package/jest.config.js +204 -0
  18. package/package.json +85 -109
  19. package/src/cgi.ts +95 -95
  20. package/src/config.ts +97 -97
  21. package/src/errorPage.ts +286 -286
  22. package/src/fileUpload.ts +126 -132
  23. package/src/index.ts +65 -66
  24. package/src/page.ts +275 -277
  25. package/src/procedure.ts +360 -359
  26. package/src/procedureError.ts +27 -27
  27. package/src/request.ts +139 -139
  28. package/src/requestError.ts +19 -19
  29. package/src/stream.ts +26 -26
  30. package/src/trace.ts +194 -193
  31. package/test/.eslintrc.json +5 -5
  32. package/test/{cgi.ts → __tests__/cgi.ts} +96 -95
  33. package/test/{config.ts → __tests__/config.ts} +41 -41
  34. package/test/__tests__/errorPage.ts +101 -0
  35. package/test/{oracledb_mock.ts → __tests__/oracledb_mock.ts} +98 -98
  36. package/test/{server.ts → __tests__/server.ts} +495 -498
  37. package/test/{stream.ts → __tests__/stream.ts} +21 -21
  38. package/test/mock/oracledb.ts +85 -85
  39. package/test/static/static.html +1 -1
  40. package/tsconfig.json +24 -23
  41. package/tsconfig.src.json +23 -22
  42. package/test/errorPage.ts +0 -101
  43. package/test/mocha.opts +0 -7
  44. package/tsconfig.test.json +0 -19
package/jest.config.js ADDED
@@ -0,0 +1,204 @@
1
+ /*
2
+ * For a detailed explanation regarding each configuration property, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ module.exports = {
7
+ // All imported modules in your tests should be mocked automatically
8
+ // automock: false,
9
+
10
+ // Stop running tests after `n` failures
11
+ // bail: 0,
12
+
13
+ // The directory where Jest should store its cached dependency information
14
+ // cacheDirectory: "/private/var/folders/2y/kvrr5nws6xz4nx9vnwjxj17w0000gn/T/jest_dx",
15
+
16
+ // Automatically clear mock calls, instances, contexts and results before every test
17
+ // clearMocks: false,
18
+
19
+ // Indicates whether the coverage information should be collected while executing the test
20
+ collectCoverage: true,
21
+
22
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
23
+ // collectCoverageFrom: undefined,
24
+ collectCoverageFrom: ['./src/**/*.{ts,js}'],
25
+
26
+ // The directory where Jest should output its coverage files
27
+ coverageDirectory: "coverage",
28
+
29
+ // An array of regexp pattern strings used to skip coverage collection
30
+ // coveragePathIgnorePatterns: [
31
+ // "/node_modules/"
32
+ // ],
33
+
34
+ // Indicates which provider should be used to instrument code for coverage
35
+ coverageProvider: "v8",
36
+
37
+ // A list of reporter names that Jest uses when writing coverage reports
38
+ // coverageReporters: [
39
+ // "json",
40
+ // "text",
41
+ // "lcov",
42
+ // "clover"
43
+ // ],
44
+
45
+ // An object that configures minimum threshold enforcement for coverage results
46
+ // coverageThreshold: undefined,
47
+
48
+ // A path to a custom dependency extractor
49
+ // dependencyExtractor: undefined,
50
+
51
+ // Make calling deprecated APIs throw helpful error messages
52
+ // errorOnDeprecated: false,
53
+
54
+ // The default configuration for fake timers
55
+ // fakeTimers: {
56
+ // "enableGlobally": false
57
+ // },
58
+
59
+ // Force coverage collection from ignored files using an array of glob patterns
60
+ // forceCoverageMatch: [],
61
+
62
+ // A path to a module which exports an async function that is triggered once before all test suites
63
+ // globalSetup: undefined,
64
+
65
+ // A path to a module which exports an async function that is triggered once after all test suites
66
+ // globalTeardown: undefined,
67
+
68
+ // A set of global variables that need to be available in all test environments
69
+ // globals: {},
70
+ globals: {
71
+ 'ts-jest': {
72
+ tsconfig: 'tsconfig.src.json',
73
+ diagnostics: true,
74
+ useESM: true,
75
+ }
76
+ },
77
+
78
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
79
+ // maxWorkers: "50%",
80
+
81
+ // An array of directory names to be searched recursively up from the requiring module's location
82
+ // moduleDirectories: [
83
+ // "node_modules"
84
+ // ],
85
+
86
+ // An array of file extensions your modules use
87
+ // moduleFileExtensions: [
88
+ // "js",
89
+ // "mjs",
90
+ // "cjs",
91
+ // "jsx",
92
+ // "ts",
93
+ // "tsx",
94
+ // "json",
95
+ // "node"
96
+ // ],
97
+
98
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
99
+ // moduleNameMapper: {},
100
+
101
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
102
+ // modulePathIgnorePatterns: [],
103
+
104
+ // Activates notifications for test results
105
+ // notify: false,
106
+
107
+ // An enum that specifies notification mode. Requires { notify: true }
108
+ // notifyMode: "failure-change",
109
+
110
+ // A preset that is used as a base for Jest's configuration
111
+ // preset: undefined,
112
+ preset: 'ts-jest',
113
+
114
+ // Run tests from one or more projects
115
+ // projects: undefined,
116
+
117
+ // Use this configuration option to add custom reporters to Jest
118
+ // reporters: undefined,
119
+
120
+ // Automatically reset mock state before every test
121
+ // resetMocks: false,
122
+
123
+ // Reset the module registry before running each individual test
124
+ // resetModules: false,
125
+
126
+ // A path to a custom resolver
127
+ // resolver: undefined,
128
+
129
+ // Automatically restore mock state and implementation before every test
130
+ // restoreMocks: false,
131
+
132
+ // The root directory that Jest should scan for tests and modules within
133
+ // rootDir: undefined,
134
+
135
+ // A list of paths to directories that Jest should use to search for files in
136
+ // roots: [
137
+ // "<rootDir>"
138
+ // ],
139
+
140
+ // Allows you to use a custom runner instead of Jest's default test runner
141
+ // runner: "jest-runner",
142
+
143
+ // The paths to modules that run some code to configure or set up the testing environment before each test
144
+ // setupFiles: [],
145
+
146
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
147
+ // setupFilesAfterEnv: [],
148
+
149
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
150
+ // slowTestThreshold: 5,
151
+
152
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
153
+ // snapshotSerializers: [],
154
+
155
+ // The test environment that will be used for testing
156
+ // testEnvironment: "jest-environment-node",
157
+
158
+ // Options that will be passed to the testEnvironment
159
+ // testEnvironmentOptions: {},
160
+
161
+ // Adds a location field to test results
162
+ // testLocationInResults: false,
163
+
164
+ // The glob patterns Jest uses to detect test files
165
+ // testMatch: [
166
+ // "**/__tests__/**/*.[jt]s?(x)",
167
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
168
+ // ],
169
+
170
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
171
+ // testPathIgnorePatterns: [
172
+ // "/node_modules/"
173
+ // ],
174
+
175
+ // The regexp pattern or array of patterns that Jest uses to detect test files
176
+ // testRegex: [],
177
+
178
+ // This option allows the use of a custom results processor
179
+ // testResultsProcessor: undefined,
180
+
181
+ // This option allows use of a custom test runner
182
+ // testRunner: "jest-circus/runner",
183
+
184
+ // A map from regular expressions to paths to transformers
185
+ // transform: undefined,
186
+
187
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
188
+ // transformIgnorePatterns: [
189
+ // "/node_modules/",
190
+ // "\\.pnp\\.[^\\/]+$"
191
+ // ],
192
+
193
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
194
+ // unmockedModulePathPatterns: undefined,
195
+
196
+ // Indicates whether each individual test should be reported during the run
197
+ // verbose: undefined,
198
+
199
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
200
+ // watchPathIgnorePatterns: [],
201
+
202
+ // Whether to use watchman for file crawling
203
+ // watchman: true,
204
+ };
package/package.json CHANGED
@@ -1,109 +1,85 @@
1
- {
2
- "name": "web_plsql",
3
- "version": "0.3.2",
4
- "author": "Dieter Oberkofler <dieter.oberkofler@gmail.com>",
5
- "license": "MIT",
6
- "description": "The Express Middleware for Oracle PL/SQL",
7
- "keywords": [
8
- "node",
9
- "nodejs",
10
- "express",
11
- "middleware",
12
- "mod_plsql",
13
- "plsql",
14
- "pl/sql",
15
- "oracle",
16
- "ohs",
17
- "ords",
18
- "gateway",
19
- "apex"
20
- ],
21
- "homepage": "https://github.com/doberkofler/web_plsql",
22
- "engines": {
23
- "node": ">=10"
24
- },
25
- "maintainers": [
26
- {
27
- "name": "Dieter Oberkofler",
28
- "email": "dieter.oberkofler@gmail.com"
29
- }
30
- ],
31
- "bugs": {
32
- "url": "https://github.com/doberkofler/web_plsql/issues"
33
- },
34
- "repository": {
35
- "type": "git",
36
- "url": "git://github.com/doberkofler/web_plsql.git"
37
- },
38
- "scripts": {
39
- "clean": "rimraf access.log lib trace coverage .nyc_output",
40
- "build": "tsc --project ./tsconfig.src.json",
41
- "eslint": "eslint --cache --report-unused-disable-directives \"./**/*.ts\"",
42
- "type-check": "tsc --project ./tsconfig.json --noEmit",
43
- "lint": "npm run eslint && npm run type-check",
44
- "test": "mocha",
45
- "test-cov": "npm run build && nyc mocha",
46
- "coveralls": "npm run test-cov && cat ./coverage/lcov.info | coveralls",
47
- "sample": "node examples/sample.js",
48
- "rebuild": "npm run clean && npm run lint && npm run build && npm run test",
49
- "create-package": "shx rm -f *.tgz && npm pack",
50
- "install": "npm run build"
51
- },
52
- "nyc": {
53
- "include": [
54
- "src/*.ts"
55
- ],
56
- "extension": [
57
- ".ts"
58
- ],
59
- "require": [
60
- "ts-node/register"
61
- ],
62
- "reporter": [
63
- "text-summary",
64
- "html"
65
- ],
66
- "sourceMap": true,
67
- "instrument": true,
68
- "all": true
69
- },
70
- "dependencies": {
71
- "@types/body-parser": "1.19.0",
72
- "@types/chai": "4.2.11",
73
- "@types/compression": "1.7.0",
74
- "@types/cookie-parser": "1.4.2",
75
- "@types/escape-html": "0.0.20",
76
- "@types/express": "4.17.3",
77
- "@types/mkdirp": "1.0.0",
78
- "@types/mocha": "7.0.2",
79
- "@types/morgan": "1.9.0",
80
- "@types/node": "13.9.5",
81
- "@types/oracledb": "4.2.0",
82
- "@typescript-eslint/eslint-plugin": "2.25.0",
83
- "@typescript-eslint/parser": "2.25.0",
84
- "body-parser": "1.19.0",
85
- "chai": "4.2.0",
86
- "compression": "1.7.4",
87
- "connect-multiparty": "2.2.0",
88
- "cookie-parser": "1.4.5",
89
- "coveralls": "3.0.11",
90
- "escape-html": "1.0.3",
91
- "eslint": "6.8.0",
92
- "express": "4.17.1",
93
- "express-status-monitor": "1.2.9",
94
- "http-parser-js": "0.5.2",
95
- "mkdirp": "1.0.3",
96
- "mocha": "7.1.1",
97
- "morgan": "1.10.0",
98
- "nyc": "15.0.0",
99
- "rimraf": "3.0.2",
100
- "shx": "0.3.2",
101
- "source-map-support": "0.5.16",
102
- "supertest": "4.0.2",
103
- "ts-node": "8.8.1",
104
- "typescript": "3.8.3"
105
- },
106
- "optionalDependencies": {
107
- "oracledb": "4.2.0"
108
- }
109
- }
1
+ {
2
+ "name": "web_plsql",
3
+ "version": "0.5.0",
4
+ "author": "Dieter Oberkofler <dieter.oberkofler@gmail.com>",
5
+ "license": "MIT",
6
+ "description": "The Express Middleware for Oracle PL/SQL",
7
+ "keywords": [
8
+ "node",
9
+ "nodejs",
10
+ "express",
11
+ "middleware",
12
+ "mod_plsql",
13
+ "plsql",
14
+ "pl/sql",
15
+ "oracle",
16
+ "ohs",
17
+ "ords",
18
+ "gateway",
19
+ "apex"
20
+ ],
21
+ "homepage": "https://github.com/doberkofler/web_plsql",
22
+ "engines": {
23
+ "node": ">=16"
24
+ },
25
+ "maintainers": [
26
+ {
27
+ "name": "Dieter Oberkofler",
28
+ "email": "dieter.oberkofler@gmail.com"
29
+ }
30
+ ],
31
+ "bugs": {
32
+ "url": "https://github.com/doberkofler/web_plsql/issues"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git://github.com/doberkofler/web_plsql.git"
37
+ },
38
+ "scripts": {
39
+ "clean": "rimraf access.log lib trace coverage .nyc_output",
40
+ "build": "tsc --project ./tsconfig.src.json",
41
+ "eslint": "eslint --cache --report-unused-disable-directives \"./**/*.ts\"",
42
+ "type-check": "tsc --project ./tsconfig.json --noEmit",
43
+ "lint": "npm run eslint && npm run type-check",
44
+ "test": "jest --coverage=false",
45
+ "test:coverage": "jest",
46
+ "sample": "node examples/sample.js",
47
+ "rebuild": "npm run clean && npm run lint && npm run build && npm run test",
48
+ "create-package": "shx rm -f *.tgz && npm pack",
49
+ "install": "npm run build"
50
+ },
51
+ "dependencies": {
52
+ "body-parser": "1.20.0",
53
+ "compression": "1.7.4",
54
+ "connect-multiparty": "2.2.0",
55
+ "cookie-parser": "1.4.6",
56
+ "escape-html": "1.0.3",
57
+ "express": "4.18.1",
58
+ "express-status-monitor": "1.3.4",
59
+ "http-parser-js": "0.5.6",
60
+ "mkdirp": "1.0.4",
61
+ "morgan": "1.10.0",
62
+ "oracledb": "5.3.0"
63
+ },
64
+ "devDependencies": {
65
+ "@types/body-parser": "1.19.2",
66
+ "@types/compression": "1.7.2",
67
+ "@types/cookie-parser": "1.4.3",
68
+ "@types/escape-html": "1.0.2",
69
+ "@types/mkdirp": "1.0.2",
70
+ "@types/morgan": "1.9.3",
71
+ "@types/node": "17.0.31",
72
+ "@types/oracledb": "5.2.3",
73
+ "@types/supertest": "2.0.12",
74
+ "@typescript-eslint/eslint-plugin": "5.22.0",
75
+ "@typescript-eslint/parser": "5.22.0",
76
+ "eslint": "8.15.0",
77
+ "jest": "28.1.0",
78
+ "rimraf": "3.0.2",
79
+ "shx": "0.3.4",
80
+ "supertest": "6.2.3",
81
+ "ts-jest": "28.0.2",
82
+ "ts-node": "10.7.0",
83
+ "typescript": "4.6.4"
84
+ }
85
+ }
package/src/cgi.ts CHANGED
@@ -1,95 +1,95 @@
1
- /*
2
- * Prepare the CGI information
3
- */
4
-
5
- import os from 'os';
6
- import {URL} from 'url';
7
- import express from 'express';
8
- export type environmentType = {[key: string]: string};
9
- import {oracleExpressMiddleware$options} from './config';
10
-
11
- /**
12
- * Create a CGI object
13
- *
14
- * @param {express.Request} req - The req object represents the HTTP request.
15
- * @param {oracleExpressMiddleware$options} options - the options for the middleware.
16
- * @returns {string} CGI object
17
- */
18
- export function getCGI(req: express.Request, options: oracleExpressMiddleware$options): environmentType {
19
- const PROTOCOL = req.protocol ? req.protocol.toUpperCase() : '';
20
- const CHARSET = 'UTF8';
21
- const IANA_CHARSET = 'UTF-8';
22
- const PATH = getPath(req);
23
-
24
- const DEFAULT_CGI: environmentType = {
25
- 'PLSQL_GATEWAY': 'WebDb',
26
- 'GATEWAY_IVERSION': '2',
27
- 'SERVER_SOFTWARE': 'web_plsql',
28
- 'GATEWAY_INTERFACE': 'CGI/1.1',
29
- 'SERVER_PORT': req.socket.localPort.toString(),
30
- 'SERVER_NAME': os.hostname(),
31
- 'REQUEST_METHOD': req.method,
32
- 'PATH_INFO': req.params.name,
33
- 'SCRIPT_NAME': PATH.script,
34
- 'REMOTE_ADDR': (req.ip || '').replace('::ffff:', ''),
35
- 'SERVER_PROTOCOL': PROTOCOL + '/' + req.httpVersion,
36
- 'REQUEST_PROTOCOL': PROTOCOL,
37
- 'REMOTE_USER': '',
38
- 'HTTP_COOKIE': getCookieString(req),
39
- 'HTTP_USER_AGENT': req.get('user-agent') || '',
40
- 'HTTP_HOST': req.get('host') || '',
41
- 'HTTP_ACCEPT': req.get('accept') || '',
42
- 'HTTP_ACCEPT_ENCODING': req.get('accept-encoding') || '',
43
- 'HTTP_ACCEPT_LANGUAGE': req.get('accept-language') || '',
44
- 'HTTP_REFERER': req.get('referer') || '',
45
- 'HTTP_X_FORWARDED_FOR': req.get('x-forwarded-for') || '',
46
- 'WEB_AUTHENT_PREFIX': '',
47
- 'DAD_NAME': PATH.dad,
48
- 'DOC_ACCESS_PATH': 'doc',
49
- 'DOCUMENT_TABLE': options.doctable || '',
50
- 'PATH_ALIAS': '',
51
- 'REQUEST_CHARSET': CHARSET,
52
- 'REQUEST_IANA_CHARSET': IANA_CHARSET,
53
- 'SCRIPT_PREFIX': PATH.prefix
54
- };
55
-
56
- return Object.assign(DEFAULT_CGI, options.cgi);
57
- }
58
-
59
- /*
60
- * Create the HTTP_COOKIE string
61
- */
62
- function getCookieString(req: express.Request): string {
63
- let cookieString = '';
64
-
65
- for (const propName in req.cookies) {
66
- cookieString += propName + '=' + req.cookies[propName] + ';';
67
- }
68
-
69
- return cookieString;
70
- }
71
-
72
- /*
73
- * Get the script name and DAD name from a URL
74
- */
75
- function getPath(req: express.Request): {script: string; prefix: string; dad: string} {
76
- // create a valid url
77
- const validUrl = req.protocol + '://' + os.hostname() + req.originalUrl;
78
-
79
- // get the pathname from the url (new URL('https://example.org/abc/xyz?123').pathname => /abc/xyz)
80
- const pathname = new URL(validUrl).pathname;
81
-
82
- const tmp = trimPath(pathname.substr(0, pathname.lastIndexOf('/') + 1));
83
- const script = '/' + tmp;
84
- const prefix = '/' + tmp.substr(0, tmp.lastIndexOf('/'));
85
- const dad = tmp.substr(tmp.indexOf('/') + 1);
86
-
87
- return {script, prefix, dad};
88
- }
89
-
90
- /*
91
- * Get a path that is not enclodes in slashes
92
- */
93
- function trimPath(value: string): string {
94
- return value.replace(/^\/+|\/+$/g, '');
95
- }
1
+ /*
2
+ * Prepare the CGI information
3
+ */
4
+
5
+ import os from 'os';
6
+ import {URL} from 'url';
7
+ import express from 'express';
8
+ export type environmentType = {[key: string]: string};
9
+ import type {oracleExpressMiddleware$options} from './config';
10
+
11
+ /**
12
+ * Create a CGI object
13
+ *
14
+ * @param {express.Request} req - The req object represents the HTTP request.
15
+ * @param {oracleExpressMiddleware$options} options - the options for the middleware.
16
+ * @returns {string} CGI object
17
+ */
18
+ export function getCGI(req: express.Request, options: oracleExpressMiddleware$options): environmentType {
19
+ const PROTOCOL = req.protocol ? req.protocol.toUpperCase() : '';
20
+ const CHARSET = 'UTF8';
21
+ const IANA_CHARSET = 'UTF-8';
22
+ const PATH = getPath(req);
23
+
24
+ const DEFAULT_CGI: environmentType = {
25
+ 'PLSQL_GATEWAY': 'WebDb',
26
+ 'GATEWAY_IVERSION': '2',
27
+ 'SERVER_SOFTWARE': 'web_plsql',
28
+ 'GATEWAY_INTERFACE': 'CGI/1.1',
29
+ 'SERVER_PORT': typeof req.socket.localPort === 'number' ? req.socket.localPort.toString() : '',
30
+ 'SERVER_NAME': os.hostname(),
31
+ 'REQUEST_METHOD': req.method,
32
+ 'PATH_INFO': req.params.name,
33
+ 'SCRIPT_NAME': PATH.script,
34
+ 'REMOTE_ADDR': (req.ip || '').replace('::ffff:', ''),
35
+ 'SERVER_PROTOCOL': PROTOCOL + '/' + req.httpVersion,
36
+ 'REQUEST_PROTOCOL': PROTOCOL,
37
+ 'REMOTE_USER': '',
38
+ 'HTTP_COOKIE': getCookieString(req),
39
+ 'HTTP_USER_AGENT': req.get('user-agent') || '',
40
+ 'HTTP_HOST': req.get('host') || '',
41
+ 'HTTP_ACCEPT': req.get('accept') || '',
42
+ 'HTTP_ACCEPT_ENCODING': req.get('accept-encoding') || '',
43
+ 'HTTP_ACCEPT_LANGUAGE': req.get('accept-language') || '',
44
+ 'HTTP_REFERER': req.get('referer') || '',
45
+ 'HTTP_X_FORWARDED_FOR': req.get('x-forwarded-for') || '',
46
+ 'WEB_AUTHENT_PREFIX': '',
47
+ 'DAD_NAME': PATH.dad,
48
+ 'DOC_ACCESS_PATH': 'doc',
49
+ 'DOCUMENT_TABLE': options.doctable || '',
50
+ 'PATH_ALIAS': '',
51
+ 'REQUEST_CHARSET': CHARSET,
52
+ 'REQUEST_IANA_CHARSET': IANA_CHARSET,
53
+ 'SCRIPT_PREFIX': PATH.prefix
54
+ };
55
+
56
+ return Object.assign(DEFAULT_CGI, options.cgi);
57
+ }
58
+
59
+ /*
60
+ * Create the HTTP_COOKIE string
61
+ */
62
+ function getCookieString(req: express.Request): string {
63
+ let cookieString = '';
64
+
65
+ for (const propName in req.cookies) {
66
+ cookieString += propName + '=' + req.cookies[propName] + ';';
67
+ }
68
+
69
+ return cookieString;
70
+ }
71
+
72
+ /*
73
+ * Get the script name and DAD name from a URL
74
+ */
75
+ function getPath(req: express.Request): {script: string; prefix: string; dad: string} {
76
+ // create a valid url
77
+ const validUrl = req.protocol + '://' + os.hostname() + req.originalUrl;
78
+
79
+ // get the pathname from the url (new URL('https://example.org/abc/xyz?123').pathname => /abc/xyz)
80
+ const pathname = new URL(validUrl).pathname;
81
+
82
+ const tmp = trimPath(pathname.substr(0, pathname.lastIndexOf('/') + 1));
83
+ const script = '/' + tmp;
84
+ const prefix = '/' + tmp.substr(0, tmp.lastIndexOf('/'));
85
+ const dad = tmp.substr(tmp.indexOf('/') + 1);
86
+
87
+ return {script, prefix, dad};
88
+ }
89
+
90
+ /*
91
+ * Get a path that is not enclodes in slashes
92
+ */
93
+ function trimPath(value: string): string {
94
+ return value.replace(/^\/+|\/+$/g, '');
95
+ }