Skip to content

Commit 6fcf927

Browse files
chore: wip
1 parent 29406ca commit 6fcf927

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

app/Actions/ExampleScheduledAction.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/Jobs/ExampleJob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default new Job({
1414
factor: 3,
1515
},
1616
handle: (payload: any) => {
17-
console.log('test')
17+
return payload
1818
},
1919
// action: 'SendWelcomeEmail', // instead of handle, you may target an action or `action: () => {`
2020
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export * from './request'
33
export * from './response'
44
export * from './router'
55
export * from './server'
6+
export * from './static'
67
export * from './utils'

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import { path as p } from '@stacksjs/path'
77
import { fs } from '@stacksjs/storage'
88
import { kebabCase, pascalCase } from '@stacksjs/strings'
99
import { customValidate, isObjectNotEmpty } from '@stacksjs/validation'
10+
import { StaticRouteManager } from './static'
1011
import { extractDefaultRequest, findRequestInstance } from './utils'
1112

1213
type ActionPath = string
1314

1415
export class Router implements RouterInterface {
1516
private routes: Route[] = []
1617
private path = ''
18+
private staticManager: StaticRouteManager = new StaticRouteManager()
1719

1820
private addRoute(
1921
method: Route['method'],
@@ -135,12 +137,20 @@ export class Router implements RouterInterface {
135137
return this.addRoute('POST', uri, callback, 201)
136138
}
137139

138-
public view(path: Route['url'], callback: Route['callback']): this {
140+
public view(path: Route['url'], htmlFile: any): this {
139141
this.path = this.normalizePath(path)
140-
141142
const uri = this.prepareUri(this.path)
142143

143-
return this.addRoute('GET', uri, callback, 200)
144+
// Add to static manager
145+
this.staticManager.addHtmlFile(uri, htmlFile)
146+
147+
// Register as a route for consistency
148+
return this.addRoute('GET', uri, async () => htmlFile, 200)
149+
}
150+
151+
// New method to get static configuration
152+
public getStaticConfig(): Record<string, any> {
153+
return this.staticManager.getStaticConfig()
144154
}
145155

146156
public redirect(path: Route['url'], callback: Route['callback'], _status?: RedirectCode): this {

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getModelName } from '@stacksjs/orm'
77
import { extname, path } from '@stacksjs/path'
88
import { fs, globSync } from '@stacksjs/storage'
99
import { isNumber } from '@stacksjs/validation'
10-
import { route } from '.'
10+
import { route, StaticRouteManager } from '.'
1111

1212
import { middlewares } from './middleware'
1313

@@ -28,11 +28,14 @@ export async function serve(options: ServeOptions = {}): Promise<void> {
2828
const hostname = options.host || 'localhost'
2929
const port = options.port || 3000
3030
const development = options.debug ? true : process.env.APP_ENV !== 'production' && process.env.APP_ENV !== 'prod'
31+
const staticManager: StaticRouteManager = new StaticRouteManager()
32+
const staticFiles = staticManager.getStaticConfig()
3133

3234
if (options.timezone)
3335
process.env.TZ = options.timezone
3436

3537
Bun.serve({
38+
static: staticFiles,
3639
hostname,
3740
port,
3841
development,
@@ -42,13 +45,6 @@ export async function serve(options: ServeOptions = {}): Promise<void> {
4245

4346
return await serverResponse(req, reqBody)
4447
},
45-
error(error: any) {
46-
return new Response(`<pre>${error}\n${error.stack}</pre>`, {
47-
headers: {
48-
'Content-Type': 'text/html',
49-
},
50-
})
51-
},
5248
})
5349
}
5450

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class StaticRouteManager {
2+
private staticRoutes: Record<string, any> = {}
3+
4+
public addHtmlFile(uri: string, htmlFile: any): void {
5+
// Normalize the URI for static serving
6+
const normalizedUri = uri.startsWith('/') ? uri : `/${uri}`
7+
// Store the HTML file with its URI
8+
this.staticRoutes[normalizedUri] = htmlFile
9+
}
10+
11+
public getStaticConfig(): Record<string, any> {
12+
return this.staticRoutes
13+
}
14+
}

storage/framework/server-auto-imports.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@
155155
"transactionRequest": true,
156156
"userRequest": true
157157
}
158-
}
158+
}

0 commit comments

Comments
 (0)