vestauth 0.18.1 → 0.18.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/CHANGELOG.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- [Unreleased](https://github.com/vestauth/vestauth/compare/v0.18.1...main)
5
+ [Unreleased](https://github.com/vestauth/vestauth/compare/v0.18.2...main)
6
+
7
+ ## [0.18.2](https://github.com/vestauth/vestauth/compare/v0.18.1...v0.18.2) (2026-02-24)
8
+
9
+ ### Changed
10
+
11
+ * Pass `--hostname` ([#35](https://github.com/vestauth/vestauth/pull/35))
6
12
 
7
13
  ## [0.18.1](https://github.com/vestauth/vestauth/compare/v0.18.0...v0.18.1) (2026-02-24)
8
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vestauth",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
4
4
  "description": "auth for agents–from the creator of dotenvx",
5
5
  "keywords": [
6
6
  "vestauth",
@@ -10,6 +10,7 @@ async function start () {
10
10
 
11
11
  await server.start({
12
12
  port: options.port,
13
+ hostname: options.hostname,
13
14
  databaseUrl: options.databaseUrl
14
15
  })
15
16
  } catch (error) {
@@ -1,8 +1,6 @@
1
1
  const { Command } = require('commander')
2
2
  const env = require('./../../lib/helpers/env')
3
3
  const databaseUrl = require('./../../lib/helpers/databaseUrl')
4
- const protocol = require('./../../lib/helpers/protocol')
5
- const hostname = require('./../../lib/helpers/hostname')
6
4
 
7
5
  const server = new Command('server')
8
6
 
@@ -15,8 +13,7 @@ const startAction = require('./../actions/server/start')
15
13
  server.command('start')
16
14
  .description('start vestauth server')
17
15
  .option('--port <port>', 'port', env('PORT'))
18
- .option('--protocol <protocol>', 'https or http', protocol())
19
- .option('--hostname <hostname>', 'localhost:3000', hostname())
16
+ .option('--hostname <hostname>', 'HOSTNAME', env('HOSTNAME'))
20
17
  .option('--database-url <databaseUrl>', 'DATABASE_URL', databaseUrl())
21
18
  .action(startAction)
22
19
 
@@ -31,7 +31,7 @@ async function dbMigrate ({ databaseUrl } = {}) {
31
31
  connection,
32
32
  ssl: { rejectUnauthorized: false },
33
33
  migrations: {
34
- directory: path.resolve(__dirname, '../../db/migrations')
34
+ directory: path.resolve(__dirname, '../../server/db/migration')
35
35
  }
36
36
  })
37
37
 
@@ -0,0 +1,34 @@
1
+ function resolvePortAndHostname ({ port, hostname } = {}) {
2
+ const hasPort = port !== undefined && port !== null && String(port).trim() !== ''
3
+ const inputPort = hasPort ? String(port).trim() : null
4
+ const inputHostname = typeof hostname === 'string' ? hostname.trim() : ''
5
+
6
+ if (!inputHostname) {
7
+ const PORT = inputPort || '3000'
8
+ return {
9
+ PORT,
10
+ HOSTNAME: `http://localhost:${PORT}`
11
+ }
12
+ }
13
+
14
+ const hasScheme = /^https?:\/\//i.test(inputHostname)
15
+ const bareHostname = hasScheme ? new URL(inputHostname).host : inputHostname
16
+ const bareHostNoPort = bareHostname.split(':')[0].toLowerCase()
17
+ const localHostnames = new Set(['localhost', '127.0.0.1'])
18
+ const defaultScheme = localHostnames.has(bareHostNoPort) ? 'http' : 'https'
19
+
20
+ const url = new URL(hasScheme ? inputHostname : `${defaultScheme}://${inputHostname}`)
21
+
22
+ const PORT = inputPort || url.port || '3000'
23
+
24
+ if (!url.port && localHostnames.has(url.hostname.toLowerCase())) {
25
+ url.port = PORT
26
+ }
27
+
28
+ return {
29
+ PORT,
30
+ HOSTNAME: url.toString().replace(/\/$/, '')
31
+ }
32
+ }
33
+
34
+ module.exports = resolvePortAndHostname
@@ -1,7 +1,7 @@
1
1
  const serverIndex = require('./../../server/index')
2
2
 
3
- function serverStart ({ port, databaseUrl }) {
4
- return serverIndex.start({ port, databaseUrl })
3
+ function serverStart ({ port, hostname, databaseUrl }) {
4
+ return serverIndex.start({ port, hostname, databaseUrl })
5
5
  }
6
6
 
7
7
  module.exports = serverStart
@@ -0,0 +1,18 @@
1
+ function subdomainBaseHost (hostname) {
2
+ if (!hostname) return null
3
+
4
+ const value = String(hostname).trim().toLowerCase()
5
+ if (!value) return null
6
+
7
+ if (value.startsWith('http://') || value.startsWith('https://')) {
8
+ try {
9
+ return new URL(value).hostname.toLowerCase()
10
+ } catch {
11
+ return null
12
+ }
13
+ }
14
+
15
+ return value.split('/')[0].split(':')[0]
16
+ }
17
+
18
+ module.exports = subdomainBaseHost
@@ -1,25 +1,31 @@
1
1
  const { logger } = require('./../shared/logger')
2
2
  const tool = require('./../lib/tool')
3
+ const resolvePortAndHostname = require('./../lib/helpers/resolvePortAndHostname')
4
+ const subdomainBaseHost = require('./../lib/helpers/subdomainBaseHost')
3
5
  const { connectOrm } = require('./models/index')
4
6
  const RegisterService = require('./services/registerService')
5
7
  const RegisterSerializer = require('./serializers/registerSerializer')
6
8
 
7
9
  const express = require('express')
8
10
 
9
- const app = express()
10
11
  let DB = null
11
12
  let HTTP_SERVER = null
12
13
  let CLOSE_PROMISE = null
13
14
  let SIGNAL_HANDLERS_INSTALLED = false
14
15
  let SIGNAL_HANDLERS = null
16
+ let PORT = null
17
+ let HOSTNAME = null
18
+
19
+ const app = express()
15
20
  app.use(express.json())
16
21
 
17
22
  app.use((req, res, next) => {
18
23
  const hostNoPort = (req.headers.host || '').split(':')[0].toLowerCase()
24
+ const baseHost = subdomainBaseHost(HOSTNAME)
19
25
 
20
- // agent-c235... .localhost
21
- if (hostNoPort.endsWith('.localhost')) {
22
- let sub = hostNoPort.slice(0, -'.localhost'.length) // "agent-c235..."
26
+ // agent-c235... .localhost or agent-c235... .example.com
27
+ if (baseHost && hostNoPort.endsWith(`.${baseHost}`)) {
28
+ let sub = hostNoPort.slice(0, -`.${baseHost}`.length) // "agent-c235..."
23
29
 
24
30
  // remove "agent-" prefix if present
25
31
  if (sub.startsWith('agent-')) {
@@ -90,8 +96,8 @@ app.get('/whoami', async (req, res) => {
90
96
  }
91
97
  })
92
98
 
93
- async function start ({ port, databaseUrl } = {}) {
94
- const PORT = port || '3000'
99
+ async function start ({ port, hostname, databaseUrl } = {}) {
100
+ ({ PORT, HOSTNAME } = resolvePortAndHostname({ port, hostname }))
95
101
 
96
102
  if (HTTP_SERVER) return HTTP_SERVER
97
103
 
@@ -102,7 +108,7 @@ async function start ({ port, databaseUrl } = {}) {
102
108
 
103
109
  HTTP_SERVER = await new Promise((resolve, reject) => {
104
110
  const server = app.listen(PORT, () => {
105
- logger.success(`vestauth server listening on http://localhost:${PORT}`)
111
+ logger.success(`vestauth server listening on ${HOSTNAME}`)
106
112
  resolve(server)
107
113
  })
108
114
 
@@ -183,5 +189,6 @@ function removeSignalHandlers () {
183
189
  module.exports = {
184
190
  app,
185
191
  start,
186
- close
192
+ close,
193
+ resolvePortAndHostname
187
194
  }
File without changes