@polylith/server 0.1.0 → 0.1.2
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 +11 -6
- package/package.json +1 -1
package/PolylithServer.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import http from 'node:http';
|
|
3
3
|
import https from 'node:https';
|
|
4
|
+
import path from 'node:path/posix';
|
|
4
5
|
import cors from 'cors';
|
|
5
6
|
import cookieParser from 'cookie-parser';
|
|
6
7
|
import cookieSession from 'cookie-session';
|
|
7
8
|
import compression from 'compression';
|
|
8
9
|
|
|
9
10
|
export class PolylithServer {
|
|
10
|
-
constructor(options) {
|
|
11
|
+
constructor(options, root) {
|
|
11
12
|
this.options = options;
|
|
13
|
+
this.staticRoot = options.dest;
|
|
14
|
+
this.root = root;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
getRouter(plApp) {
|
|
@@ -21,8 +24,12 @@ export class PolylithServer {
|
|
|
21
24
|
plApp.watch();
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
serve(
|
|
25
|
-
this.
|
|
27
|
+
serve() {
|
|
28
|
+
var roots = !Array.isArray(this.staticRoot) ? [this.staticRoot] : this.staticRoot;
|
|
29
|
+
|
|
30
|
+
roots.forEach(function(root) {
|
|
31
|
+
this.app.use(express.static(path.join(this.root, root)));
|
|
32
|
+
}, this)
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
create() {
|
|
@@ -56,9 +63,7 @@ export class PolylithServer {
|
|
|
56
63
|
.use(express.text())
|
|
57
64
|
.use(express.raw())
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
this.serve(app);
|
|
61
|
-
}, this);
|
|
66
|
+
this.serve();
|
|
62
67
|
|
|
63
68
|
if (httpsOptions)
|
|
64
69
|
this.server = https.createServer(httpsOptions, this.app);
|