Skip to content

Commit f435c31

Browse files
authored
fix:update default port number for the server from 8008 to 2311 (#26) (#27)
* fix: update default port number for the server from 8008 to 2311 * fix: bump up version * fix: enhance error handling for ZenStack module loading and server startup
2 parents db1ee09 + 9170e45 commit f435c31

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/proxy",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"description": "A CLI tool to run an Express server that proxies CRUD requests to a ZenStack backend",
55
"main": "index.js",
66
"publishConfig": {
@@ -20,7 +20,12 @@
2020
"clean": "rimraf dist",
2121
"build": "pnpm clean && tsc && copyfiles -F \"bin/*\" dist && copyfiles ./README.md ./LICENSE ./package.json dist && pnpm pack dist --pack-destination ../build"
2222
},
23-
"keywords": ["zenstack", "proxy", "express", "cli"],
23+
"keywords": [
24+
"zenstack",
25+
"proxy",
26+
"express",
27+
"cli"
28+
],
2429
"author": "",
2530
"license": "MIT",
2631
"dependencies": {
@@ -53,4 +58,4 @@
5358
"require": "./index.js"
5459
}
5560
}
56-
}
61+
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function createProgram() {
2020

2121
program
2222
.option('-z, --zenstack <path>', 'Path to ZenStack generated folder')
23-
.option('-p, --port <number>', 'Port number for the server', '8008')
23+
.option('-p, --port <number>', 'Port number for the server', '2311')
2424
.option('-s, --schema <path>', 'Path to ZModel schema file', 'schema.zmodel')
2525
.option('-d, --datasource-url <url>', 'Datasource URL (overrides schema configuration)')
2626
.option('-l, --log <level...>', 'Query log levels (e.g., query, info, warn, error)')

src/server.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cors from 'cors'
44
import { ZenStackMiddleware } from '@zenstackhq/server/express'
55
import { ZModelConfig } from './zmodel-parser'
66
import { getNodeModulesFolder, getPrismaVersion, getZenStackVersion } from './utils/version-utils'
7-
import { blue, grey } from 'colors'
7+
import { blue, grey, red } from 'colors'
88
import semver from 'semver'
99
import { CliError } from './cli-error'
1010

@@ -168,23 +168,29 @@ async function loadZenStackModules(
168168
enums = prismaModule.$Enums || {}
169169
}
170170

171-
let zenstackAbsPath = zenstackPath
171+
const zenstackAbsPath = zenstackPath
172172
? path.isAbsolute(zenstackPath)
173173
? zenstackPath
174174
: path.join(process.cwd(), zenstackPath)
175175
: undefined
176176

177-
if (zenstackAbsPath) {
178-
const modelMetaPath = path.join(zenstackAbsPath, 'model-meta')
177+
let modelMetaPath: string | undefined
178+
try {
179+
if (zenstackAbsPath) {
180+
modelMetaPath = path.join(zenstackAbsPath, 'model-meta')
181+
} else {
182+
modelMetaPath = '@zenstackhq/runtime/model-meta'
183+
}
179184
modelMeta = require(modelMetaPath).default
180-
} else {
181-
modelMeta = require('@zenstackhq/runtime/model-meta').default
185+
} catch {
186+
throw new CliError(
187+
`Failed to load ZenStack generated model meta from: ${modelMetaPath}\n` +
188+
`Please run \`zenstack generate\` first or specify the correct output directory of ZenStack generated modules using the \`-z\` option.`
189+
)
182190
}
183191

184192
if (!modelMeta.models) {
185-
throw new CliError(
186-
'ZenStack generated modules not found. Please make sure `zenstack generate` has been run or specify the correct path using the `-z` option.'
187-
)
193+
throw new CliError(`Generated model meta not found. Please run \`zenstack generate\` first.`)
188194
}
189195

190196
const zenstackVersion = getZenStackVersion()
@@ -247,6 +253,19 @@ export async function startServer(options: ServerOptions) {
247253
console.log(`ZenStack Studio is running at: ${blue('https://studio.zenstack.dev')}`)
248254
})
249255

256+
server.on('error', (err: NodeJS.ErrnoException) => {
257+
if (err.code === 'EADDRINUSE') {
258+
console.error(
259+
red(
260+
`Port ${options.port} is already in use. Please choose a different port using -p option.`
261+
)
262+
)
263+
} else {
264+
throw new CliError(`Failed to start the server: ${err.message}`)
265+
}
266+
process.exit(1)
267+
})
268+
250269
// Graceful shutdown
251270
process.on('SIGTERM', async () => {
252271
server.close(() => {

0 commit comments

Comments
 (0)