@polylith/server 0.1.4 → 0.1.5

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/PolylithServer.js CHANGED
@@ -6,12 +6,14 @@ import cors from 'cors';
6
6
  import cookieParser from 'cookie-parser';
7
7
  import cookieSession from 'cookie-session';
8
8
  import compression from 'compression';
9
+ import {workingDir} from './utils.js';
10
+
9
11
 
10
12
  export class PolylithServer {
11
- constructor(options, root) {
13
+ constructor(options, dest) {
12
14
  this.options = options;
13
- this.staticRoot = options.dest;
14
- this.root = root;
15
+ this.staticRoot = dest;
16
+ this.root = workingDir();
15
17
  }
16
18
 
17
19
  getRouter(plApp) {
@@ -34,7 +36,6 @@ export class PolylithServer {
34
36
 
35
37
  create() {
36
38
  var {
37
- apps,
38
39
  https : httpsOptions,
39
40
  cors : corsOptions,
40
41
  compression: useCompression,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polylith/server",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "This is the basic polylith http/https server. It is build on top of Express.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js ADDED
@@ -0,0 +1,46 @@
1
+ import path from 'node:path/posix';
2
+ import {readFile, writeFile, stat} from 'node:fs/promises';
3
+ import {cwd} from 'node:process';
4
+
5
+ /**
6
+ * call this function to force the file path to use posix notation and remove
7
+ * all drive information.
8
+ *
9
+ *
10
+ * @param {String} src the filename wqe
11
+ * @returns {String} the new path
12
+ */
13
+ export function forceToPosix(src) {
14
+ src = src.replace('file:', '');
15
+ src = src.replace('///', '');
16
+ src = src.replace(/.*?:/, '');
17
+ src = src.replace(/\\/g, '/');
18
+
19
+ return src;
20
+ }
21
+
22
+ export function workingDir() {
23
+ return forceToPosix(process.cwd());
24
+ }
25
+
26
+ export function fileToPath(filename) {
27
+ filename = forceToPosix(filename);
28
+ return path.dirname(filename);
29
+ }
30
+
31
+
32
+ /**
33
+ * call this function to check if the given file exists
34
+ *
35
+ * @param {String} path the name of the file
36
+ * @returns {Promise<Boolean>} true if the file exists
37
+ */
38
+
39
+ export async function fileExists(path) {
40
+ try {
41
+ await stat(path)
42
+ return true;
43
+ } catch (e) {
44
+ return false;
45
+ }
46
+ }