@ossy/app 0.7.15 → 0.7.16
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/README.md +22 -0
- package/cli/server.js +23 -2
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# `@ossy/app`
|
|
2
|
+
|
|
3
|
+
Server-side rendering runtime for Ossy apps.
|
|
4
|
+
|
|
5
|
+
## Port configuration
|
|
6
|
+
|
|
7
|
+
By default, the server listens on port **3000**.
|
|
8
|
+
|
|
9
|
+
- **Environment variable**: set `PORT`
|
|
10
|
+
- **CLI argument**: pass `--port <number>` (or `-p <number>`) when running the built server file
|
|
11
|
+
|
|
12
|
+
Examples:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# env var
|
|
16
|
+
PORT=4000 node build/server.js
|
|
17
|
+
|
|
18
|
+
# CLI arg
|
|
19
|
+
node build/server.js --port 4000
|
|
20
|
+
node build/server.js -p 4000
|
|
21
|
+
```
|
|
22
|
+
|
package/cli/server.js
CHANGED
|
@@ -17,6 +17,27 @@ const app = express();
|
|
|
17
17
|
const currentDir = path.dirname(url.fileURLToPath(import.meta.url))
|
|
18
18
|
const ROOT_PATH = path.resolve(currentDir, 'public')
|
|
19
19
|
|
|
20
|
+
function parsePortFromArgv(argv) {
|
|
21
|
+
// Supports: --port 4000, --port=4000, -p 4000
|
|
22
|
+
const idx = argv.findIndex(a => a === '--port' || a === '-p')
|
|
23
|
+
if (idx !== -1 && argv[idx + 1]) return argv[idx + 1]
|
|
24
|
+
|
|
25
|
+
const eq = argv.find(a => a.startsWith('--port='))
|
|
26
|
+
if (eq) return eq.split('=')[1]
|
|
27
|
+
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function normalizePort(value, fallback) {
|
|
32
|
+
if (value === undefined || value === null || value === '') return fallback
|
|
33
|
+
const n = Number.parseInt(String(value), 10)
|
|
34
|
+
if (!Number.isFinite(n) || n <= 0) return fallback
|
|
35
|
+
return n
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const DEFAULT_PORT = 3000
|
|
39
|
+
const port = normalizePort(parsePortFromArgv(process.argv) ?? process.env.PORT, DEFAULT_PORT)
|
|
40
|
+
|
|
20
41
|
if (Middleware !== undefined) {
|
|
21
42
|
console.log(`[@ossy/app][server] ${Middleware?.length || 0} custom middleware loaded`)
|
|
22
43
|
}
|
|
@@ -72,8 +93,8 @@ app.all('*all', (req, res) => {
|
|
|
72
93
|
|
|
73
94
|
});
|
|
74
95
|
|
|
75
|
-
app.listen(
|
|
76
|
-
console.log(
|
|
96
|
+
app.listen(port, () => {
|
|
97
|
+
console.log(`[@ossy/app][server] Running on http://localhost:${port}`);
|
|
77
98
|
});
|
|
78
99
|
|
|
79
100
|
async function renderToString(App, config) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"/cli",
|
|
59
59
|
"README.md"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "2a788e4868aa7ed2b0bc9869533f926d4cf6828a"
|
|
62
62
|
}
|