Skip to content

Commit 17a9ade

Browse files
committed
chore: wip
1 parent 29382ae commit 17a9ade

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

app/Actions/HealthAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Action } from '@stacksjs/actions'
44
export default new Action({
55
name: 'Health',
66
description: 'A health check for your application.',
7+
path: '/api/health',
78

89
handle() {
910
return {

bun.lockb

18.2 KB
Binary file not shown.

routes/api.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import { route } from '@stacksjs/router'
88
* @see https://stacksjs.org/docs/routing
99
*/
1010

11-
// route.get('/', () => 'hello world') // $APP_URL/api
11+
// $APP_URL/api
12+
await route.get('/', () => 'hello world')
1213

13-
route.get('/welcome', () => { // stacksjs.org/api/welcome
14+
// $APP_URL/api/welcome
15+
await route.get('/welcome', () => {
1416
return { // you may return an object as well
1517
data: 'hello world, friend',
1618
}
1719
})
1820

19-
// route.get('/hello/world', () => 'hello world, buddy') // stacksjs.org/api/hello/world
21+
route.get('/hello/world', () => 'hello world, buddy') // stacksjs.org/api/hello/world
2022

2123
// route.group('/buddy', () => { // you may group your routes in a few different ways
2224
// route.get('/commands', 'Actions/Buddy/CommandsAction')
@@ -32,4 +34,4 @@ route.get('/welcome', () => { // stacksjs.org/api/welcome
3234
// route.action('/example') // the equivalent of route.get('/example', 'ExampleAction')
3335
// route.job('/example-two') // the equivalent of route.get('/example-two', 'ExampleTwoJob')
3436

35-
// route.health() // adds an `/api/health` route
37+
route.health() // adds an `/api/health` route

storage/framework/api/dev.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import { join, path } from '@stacksjs/path'
77
import { italic, log, runCommandSync } from '@stacksjs/cli'
88

99
declare global {
10-
var count: number
10+
let counter: number
1111
}
1212

13-
globalThis.count ??= 0
14-
log.debug(`Reloaded ${globalThis.count} times`)
15-
globalThis.count++
13+
// @ts-expect-error - somehow type is not recognized
14+
globalThis.counter ??= 0
15+
// @ts-expect-error - somehow type is not recognized
16+
log.debug(`Reloaded ${globalThis.counter} times`)
17+
// @ts-expect-error - somehow type is not recognized
18+
globalThis.counter++
1619

1720
async function watchFolders() {
1821
const coreDirectories = await readdir(path.corePath(), { withFileTypes: true })
@@ -48,7 +51,8 @@ async function watchFolders() {
4851
})
4952
}
5053

51-
if (globalThis.count === 1)
54+
// @ts-expect-error - somehow type is not recognized
55+
if (globalThis.counter === 1)
5256
watchFolders().catch(log.error)
5357
else
5458
log.debug(`Skipping watching folders`)
@@ -64,7 +68,8 @@ process.on('SIGINT', () => {
6468
process.exit()
6569
})
6670

67-
if (globalThis.count === 1)
68-
log.info(`Listening on http://localhost:3999...`)
69-
else
70-
log.info(`#${globalThis.count}: Listening on http://localhost:3999...`)
71+
// @ts-expect-error - somehow type is not recognized
72+
if (globalThis.counter === 1)
73+
log.info(`Listening on http://localhost:3999/api ...`)
74+
else // @ts-expect-error - somehow type is not recognized
75+
log.info(`#${globalThis.counter}: Listening on http://localhost:3999/api ...`)

storage/framework/core/router/src/router.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export class Router implements RouterInterface {
4141
routeCallback = callback
4242
}
4343

44+
log.debug(`Adding route: ${method} ${uri} with name ${name}`)
45+
4446
this.routes.push({
4547
name,
4648
method,
@@ -62,7 +64,7 @@ export class Router implements RouterInterface {
6264
callback = await this.resolveCallback(callback)
6365

6466
const uri = this.prepareUri(this.path)
65-
log.debug(`Prepared URI: ${uri}`) // should be debug
67+
log.debug(`Prepared URI: ${uri}`)
6668

6769
return this.addRoute('GET', uri, callback, 200)
6870
}
@@ -71,7 +73,9 @@ export class Router implements RouterInterface {
7173
const healthModule = await import(p.userActionsPath('HealthAction.ts'))
7274
const callback = healthModule.default.handle
7375

74-
this.addRoute('GET', `${this.apiPrefix}/health`, callback, 200)
76+
const path = healthModule.default.path ?? `${this.apiPrefix}/health`
77+
78+
this.addRoute('GET', path, callback, 200)
7579

7680
return this
7781
}
@@ -152,7 +156,7 @@ export class Router implements RouterInterface {
152156
cb = callback
153157
}
154158

155-
const { prefix = '', middleware = [] } = options
159+
const { prefix = '', middleware = [] } = options as RouteGroupOptions
156160

157161
// Save a reference to the original routes array
158162
const originalRoutes = this.routes
@@ -273,7 +277,7 @@ export class Router implements RouterInterface {
273277
path = `${this.apiPrefix}${this.groupPrefix}/${path}`
274278

275279
// if path ends in "/", then remove it
276-
// possibly triggered when route is "/"
280+
// e.g. triggered when route is "/"
277281
return path.endsWith('/') ? path.slice(0, -1) : path
278282
}
279283

0 commit comments

Comments
 (0)