appstage 0.2.29 → 0.3.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.
package/dist/bin.js CHANGED
@@ -767,10 +767,8 @@ async function run() {
767
767
  if (scriptName === "build") return await cli(args);
768
768
  let nodeEnv = nodeEnvMap[scriptName];
769
769
  if (nodeEnv !== void 0) process.env.NODE_ENV = nodeEnv;
770
- if (args.length !== 0 && !(0, import_args_json2.isKey)(args[0])) {
771
- let [hostname, port] = args[0].split(":");
772
- if (hostname) process.env.APP_HOST = hostname;
773
- if (port) process.env.APP_PORT = port;
770
+ if (args.length !== 0 && args[0] && !(0, import_args_json2.isKey)(args[0])) {
771
+ process.env.SERVER_URL = args[0];
774
772
  args.shift();
775
773
  }
776
774
  if (!(0, import_args_json2.hasKey)("--client-dir")) args.push("--client-dir", "src/public/-");
package/dist/index.cjs CHANGED
@@ -672,6 +672,33 @@ async function cli(input = []) {
672
672
  await build(params);
673
673
  }
674
674
 
675
+ const defaultPorts = {
676
+ "http:": 80,
677
+ "https:": 443
678
+ };
679
+ function getServerURL() {
680
+ let { SERVER_URL: href, SERVER_HOSTNAME: hostname = "localhost", SERVER_PORT: port = "3000" } = process.env;
681
+ let protocol = "http:";
682
+ if (href) {
683
+ if (href.startsWith("//")) href = `${protocol}${href}`;
684
+ else if (!href.includes("://")) href = `${protocol}//${href}`;
685
+ else protocol = href.slice(0, href.indexOf("://") + 1);
686
+ let matches = href.match(/^\w+:\/\/([^/:]+)(:(\d+))?(\/|$)/);
687
+ if (matches?.[1]) hostname = matches[1];
688
+ if (matches?.[3]) port = matches[3];
689
+ } else href = `${protocol}//${hostname}:${port}`;
690
+ let parsedPort = Number(port);
691
+ let origin = `${protocol}//${hostname}`;
692
+ if (parsedPort !== defaultPorts[protocol]) origin += `:${port}`;
693
+ return {
694
+ href,
695
+ origin,
696
+ protocol,
697
+ hostname,
698
+ port: parsedPort
699
+ };
700
+ }
701
+
675
702
  const renderStatus = async (req, res) => {
676
703
  let { id, nonce } = req.ctx;
677
704
  let statusText = `${res.statusCode} ${node_http.STATUS_CODES[res.statusCode]}`;
@@ -682,11 +709,10 @@ const renderStatus = async (req, res) => {
682
709
  function createApp(callback) {
683
710
  let app = (0, express.default)();
684
711
  if (!app.events) app.events = new node_events.default();
685
- let host = process.env.APP_HOST || "localhost";
686
- let port = Number(process.env.APP_PORT) || 3e3;
687
712
  let listen = () => {
688
- app.listen(port, host, () => {
689
- emitLog(app, `Server running at ${`http://${host}:${port}/`} (${`NODE_ENV=${process.env.NODE_ENV}`})`);
713
+ let { href, protocol, hostname, port } = getServerURL();
714
+ if (protocol === "http:") app.listen(port, hostname, () => {
715
+ emitLog(app, `Server running at ${href} (NODE_ENV=${process.env.NODE_ENV})`);
690
716
  });
691
717
  };
692
718
  if (process.env.NODE_ENV === "development") app.events?.on("log", ({ message, ...payload }) => {
@@ -742,6 +768,7 @@ exports.emitLog = emitLog;
742
768
  exports.files = files;
743
769
  exports.getEffectiveLocale = getEffectiveLocale;
744
770
  exports.getLocales = getLocales;
771
+ exports.getServerURL = getServerURL;
745
772
  exports.getStatusMessage = getStatusMessage;
746
773
  exports.init = init;
747
774
  exports.injectNonce = injectNonce;
package/dist/index.d.ts CHANGED
@@ -1127,6 +1127,14 @@ declare const cspNonce: (req: IncomingMessage) => string;
1127
1127
 
1128
1128
  declare function emitLog(app: Application, message?: LogEventPayload["message"] | LogEventPayload, payload?: LogEventPayload): any;
1129
1129
 
1130
+ declare function getServerURL(): {
1131
+ href: string;
1132
+ origin: string;
1133
+ protocol: string;
1134
+ hostname: string;
1135
+ port: number;
1136
+ };
1137
+
1130
1138
  declare function getStatusMessage(prefix: string, statusCode: number): string;
1131
1139
 
1132
1140
  declare const injectNonce: TransformContent;
@@ -1142,4 +1150,4 @@ declare function servePipeableStream(req: Request, res: Response): ({
1142
1150
  pipe
1143
1151
  }: PipeableStream, error?: unknown) => Promise<void>;
1144
1152
 
1145
- export { Controller, ErrorController, FilesParams, LangParams, LogEventPayload, LogLevel, LogOptions, Middleware, MiddlewareSet, RedirectParams, RenderStatus, ReqCtx, TransformContent, build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getStatusMessage, init, injectNonce, lang, log, redirect, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
1153
+ export { Controller, ErrorController, FilesParams, LangParams, LogEventPayload, LogLevel, LogOptions, Middleware, MiddlewareSet, RedirectParams, RenderStatus, ReqCtx, TransformContent, build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getServerURL, getStatusMessage, init, injectNonce, lang, log, redirect, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
package/dist/index.mjs CHANGED
@@ -646,6 +646,33 @@ async function cli(input = []) {
646
646
  await build(params);
647
647
  }
648
648
 
649
+ const defaultPorts = {
650
+ "http:": 80,
651
+ "https:": 443
652
+ };
653
+ function getServerURL() {
654
+ let { SERVER_URL: href, SERVER_HOSTNAME: hostname = "localhost", SERVER_PORT: port = "3000" } = process.env;
655
+ let protocol = "http:";
656
+ if (href) {
657
+ if (href.startsWith("//")) href = `${protocol}${href}`;
658
+ else if (!href.includes("://")) href = `${protocol}//${href}`;
659
+ else protocol = href.slice(0, href.indexOf("://") + 1);
660
+ let matches = href.match(/^\w+:\/\/([^/:]+)(:(\d+))?(\/|$)/);
661
+ if (matches?.[1]) hostname = matches[1];
662
+ if (matches?.[3]) port = matches[3];
663
+ } else href = `${protocol}//${hostname}:${port}`;
664
+ let parsedPort = Number(port);
665
+ let origin = `${protocol}//${hostname}`;
666
+ if (parsedPort !== defaultPorts[protocol]) origin += `:${port}`;
667
+ return {
668
+ href,
669
+ origin,
670
+ protocol,
671
+ hostname,
672
+ port: parsedPort
673
+ };
674
+ }
675
+
649
676
  const renderStatus = async (req, res) => {
650
677
  let { id, nonce } = req.ctx;
651
678
  let statusText = `${res.statusCode} ${STATUS_CODES[res.statusCode]}`;
@@ -656,11 +683,10 @@ const renderStatus = async (req, res) => {
656
683
  function createApp(callback) {
657
684
  let app = express();
658
685
  if (!app.events) app.events = new EventEmitter();
659
- let host = process.env.APP_HOST || "localhost";
660
- let port = Number(process.env.APP_PORT) || 3e3;
661
686
  let listen = () => {
662
- app.listen(port, host, () => {
663
- emitLog(app, `Server running at ${`http://${host}:${port}/`} (${`NODE_ENV=${process.env.NODE_ENV}`})`);
687
+ let { href, protocol, hostname, port } = getServerURL();
688
+ if (protocol === "http:") app.listen(port, hostname, () => {
689
+ emitLog(app, `Server running at ${href} (NODE_ENV=${process.env.NODE_ENV})`);
664
690
  });
665
691
  };
666
692
  if (process.env.NODE_ENV === "development") app.events?.on("log", ({ message, ...payload }) => {
@@ -708,4 +734,4 @@ function servePipeableStream(req, res) {
708
734
  };
709
735
  }
710
736
 
711
- export { build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getStatusMessage, init, injectNonce, lang, log, redirect, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
737
+ export { build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getServerURL, getStatusMessage, init, injectNonce, lang, log, redirect, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
package/index.ts CHANGED
@@ -24,6 +24,7 @@ export * from "./src/types/TransformContent.ts";
24
24
  export * from "./src/utils/createApp.ts";
25
25
  export * from "./src/utils/cspNonce.ts";
26
26
  export * from "./src/utils/emitLog.ts";
27
+ export * from "./src/utils/getServerURL.ts";
27
28
  export * from "./src/utils/getStatusMessage.ts";
28
29
  export * from "./src/utils/injectNonce.ts";
29
30
  export * from "./src/utils/renderStatus.ts";
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "appstage",
3
- "version": "0.2.29",
4
- "description": "",
5
- "main": "./dist/index.cjs",
6
- "module": "./dist/index.mjs",
7
- "types": "./dist/index.d.ts",
8
- "type": "module",
9
- "bin": {
10
- "appstage": "./dist/bin.js"
11
- },
12
- "scripts": {
13
- "compile-bin": "esbuild src/scripts/bin.ts --bundle --outfile=dist/bin.js --platform=node --external:esbuild --format=esm",
14
- "preversion": "npx npm-run-all shape compile-bin",
15
- "shape": "npx codeshape",
16
- "typecheck": "npx codeshape typecheck"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/axtk/appstage.git"
21
- },
22
- "author": "axtk",
23
- "license": "MIT",
24
- "peerDependencies": {
25
- "express": ">=5"
26
- },
27
- "devDependencies": {
28
- "@types/express": "^5.0.6",
29
- "@types/node": "^25.4.0"
30
- },
31
- "dependencies": {
32
- "args-json": "^1.4.3",
33
- "dateshape": "^1.1.2",
34
- "esbuild": "^0.28.0"
35
- }
36
- }
1
+ {
2
+ "name": "appstage",
3
+ "version": "0.3.0",
4
+ "description": "",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "type": "module",
9
+ "bin": {
10
+ "appstage": "./dist/bin.js"
11
+ },
12
+ "scripts": {
13
+ "compile-bin": "esbuild src/scripts/bin.ts --bundle --outfile=dist/bin.js --platform=node --external:esbuild --format=esm",
14
+ "preversion": "npx npm-run-all shape compile-bin",
15
+ "shape": "npx codeshape",
16
+ "typecheck": "npx codeshape typecheck"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/axtk/appstage.git"
21
+ },
22
+ "author": "axtk",
23
+ "license": "MIT",
24
+ "peerDependencies": {
25
+ "express": ">=5"
26
+ },
27
+ "devDependencies": {
28
+ "@types/express": "^5.0.6",
29
+ "@types/node": "^25.4.0"
30
+ },
31
+ "dependencies": {
32
+ "args-json": "^1.4.3",
33
+ "dateshape": "^1.1.2",
34
+ "esbuild": "^0.28.0"
35
+ }
36
+ }
@@ -23,12 +23,8 @@ async function run() {
23
23
 
24
24
  if (nodeEnv !== undefined) process.env.NODE_ENV = nodeEnv;
25
25
 
26
- if (args.length !== 0 && !isKey(args[0])) {
27
- let [hostname, port] = args[0].split(":");
28
-
29
- if (hostname) process.env.APP_HOST = hostname;
30
- if (port) process.env.APP_PORT = port;
31
-
26
+ if (args.length !== 0 && args[0] && !isKey(args[0])) {
27
+ process.env.SERVER_URL = args[0];
32
28
  args.shift();
33
29
  }
34
30
 
@@ -5,6 +5,7 @@ import { init } from "../middleware/init.ts";
5
5
  import { requestEvents } from "../middleware/requestEvents.ts";
6
6
  import type { LogEventPayload } from "../types/LogEventPayload.ts";
7
7
  import { emitLog } from "./emitLog.ts";
8
+ import { getServerURL } from "./getServerURL.ts";
8
9
  import { renderStatus } from "./renderStatus.ts";
9
10
 
10
11
  export function createApp(callback?: () => void | Promise<void>) {
@@ -12,16 +13,16 @@ export function createApp(callback?: () => void | Promise<void>) {
12
13
 
13
14
  if (!app.events) app.events = new EventEmitter();
14
15
 
15
- let host = process.env.APP_HOST || "localhost";
16
- let port = Number(process.env.APP_PORT) || 3000;
17
-
18
16
  let listen = () => {
19
- app.listen(port, host, () => {
20
- let location = `http://${host}:${port}/`;
21
- let env = `NODE_ENV=${process.env.NODE_ENV}`;
22
-
23
- emitLog(app, `Server running at ${location} (${env})`);
24
- });
17
+ let { href, protocol, hostname, port } = getServerURL();
18
+
19
+ if (protocol === "http:")
20
+ app.listen(port, hostname, () => {
21
+ emitLog(
22
+ app,
23
+ `Server running at ${href} (NODE_ENV=${process.env.NODE_ENV})`,
24
+ );
25
+ });
25
26
  };
26
27
 
27
28
  if (process.env.NODE_ENV === "development")
@@ -0,0 +1,38 @@
1
+ const defaultPorts: Record<string, number> = {
2
+ "http:": 80,
3
+ "https:": 443,
4
+ };
5
+
6
+ export function getServerURL() {
7
+ let {
8
+ SERVER_URL: href,
9
+ SERVER_HOSTNAME: hostname = "localhost",
10
+ SERVER_PORT: port = "3000",
11
+ } = process.env;
12
+
13
+ let protocol = "http:";
14
+
15
+ if (href) {
16
+ if (href.startsWith("//")) href = `${protocol}${href}`;
17
+ else if (!href.includes("://")) href = `${protocol}//${href}`;
18
+ else protocol = href.slice(0, href.indexOf("://") + 1);
19
+
20
+ let matches = href.match(/^\w+:\/\/([^/:]+)(:(\d+))?(\/|$)/);
21
+
22
+ if (matches?.[1]) hostname = matches[1];
23
+ if (matches?.[3]) port = matches[3];
24
+ } else href = `${protocol}//${hostname}:${port}`;
25
+
26
+ let parsedPort = Number(port);
27
+ let origin = `${protocol}//${hostname}`;
28
+
29
+ if (parsedPort !== defaultPorts[protocol]) origin += `:${port}`;
30
+
31
+ return {
32
+ href,
33
+ origin,
34
+ protocol,
35
+ hostname,
36
+ port: parsedPort,
37
+ };
38
+ }