miqro 1.7.8 → 1.7.9

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 (2) hide show
  1. package/dist/cmds/serve.js +41 -6
  2. package/package.json +2 -2
@@ -2,19 +2,54 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.main = void 0;
4
4
  const core_1 = require("@miqro/core");
5
+ const utils_1 = require("../utils");
6
+ const url_1 = require("url");
7
+ const tokenize_match_1 = require("@miqro/core/dist/common/tokenize-match");
5
8
  const main = () => {
6
- if (process.argv.length <= 3 || process.argv.length > 5) {
7
- throw new Error(`invalid number of args\nusage: [PORT=8080] npx miqro serve <directory> [path=/]`);
9
+ const flags = (0, utils_1.extractFlags)(process.argv.slice(3), {
10
+ flags: {
11
+ "proxy": {
12
+ description: "proxy",
13
+ hasValue: true
14
+ },
15
+ "port": {
16
+ description: "port",
17
+ hasValue: true
18
+ }
19
+ }
20
+ });
21
+ if (flags.files.length > 2) {
22
+ throw new Error(`invalid number of args\nusage: [PORT=8080] npx miqro serve [directory=./] [path=/]`);
23
+ }
24
+ if (flags.flags.port instanceof Array) {
25
+ throw new Error(`invalid number of args\nusage: [PORT=8080] npx miqro serve [directory=./] [path=/] [--port 8080] [--proxy /api=https://host/api]`);
8
26
  }
9
- const directory = process.argv[3];
10
- const path = process.argv[4] ? process.argv[4] : "/";
27
+ let [directory, path] = flags.files;
28
+ path = path ? path : "/";
29
+ directory = directory ? directory : process.cwd();
11
30
  (0, core_1.loadConfig)();
12
- const PORT = process.env.PORT ? process.env.PORT : 8080;
31
+ const PORT = flags.flags.port ? flags.flags.port : (process.env.PORT ? process.env.PORT : 8080);
13
32
  if (PORT === undefined) {
14
- throw new Error("PORT env var not defined");
33
+ throw new Error("port not defined");
15
34
  }
16
35
  const app = new core_1.App();
17
36
  app.use((0, core_1.LoggerHandler)());
37
+ const proxyList = flags.flags.proxy instanceof Array ? flags.flags.proxy : [flags.flags.proxy];
38
+ for (const proxy of proxyList) {
39
+ if (proxy) {
40
+ const proxySplit = proxy.split("=");
41
+ if (proxySplit.length !== 2) {
42
+ throw new Error("proxy must be in the form. /path=proxy");
43
+ }
44
+ const proxyPath = (0, tokenize_match_1.normalizePath)(proxySplit[0]);
45
+ const proxyURL = new url_1.URL(proxySplit[1]);
46
+ proxyURL.pathname = (0, tokenize_match_1.normalizePath)(proxyURL.pathname);
47
+ app.use((0, core_1.ReadBuffer)());
48
+ app.use((0, core_1.Proxy)({
49
+ url: proxyURL.toString()
50
+ }), proxyPath);
51
+ }
52
+ }
18
53
  app.use((0, core_1.Static)({
19
54
  directory,
20
55
  list: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "1.7.8",
3
+ "version": "1.7.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "author": "claukers",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@miqro/core": "^1.5.4",
20
+ "@miqro/core": "^1.5.6",
21
21
  "@miqro/parser": "^0.0.2",
22
22
  "@miqro/runner": "^1.2.4",
23
23
  "@miqro/test": "^0.0.9",