Skip to content

Commit d52e1fb

Browse files
committed
chore: wip
1 parent 041a16c commit d52e1fb

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

routes/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { route } from '@stacksjs/router'
2-
// const { route } = await import('@stacksjs/router')
32

43
/**
54
* This file is the entry point for your application's API routes.

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ export async function serverResponse(req: Request, body: string) {
5151
// This automatically allows for route definitions, like
5252
// '/about' and '/about/' to be treated as the same
5353
const trimmedUrl = req.url.endsWith('/') && req.url.length > 1 ? req.url.slice(0, -1) : req.url
54-
5554
const url = new URL(trimmedUrl)
56-
5755
const routesList: Route[] = await route.getRoutes()
56+
5857
log.info(`Routes List: ${JSON.stringify(routesList)}`, { styled: false })
5958
log.info(`URL: ${JSON.stringify(url)}`, { styled: false })
6059

@@ -145,7 +144,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
145144

146145
const { status, ...payloadWithoutStatus } = middlewarePayload
147146

148-
return await new Response(JSON.stringify(payloadWithoutStatus), {
147+
return new Response(JSON.stringify(payloadWithoutStatus), {
149148
headers: {
150149
'Content-Type': 'json',
151150
'Access-Control-Allow-Origin': '*',
@@ -161,7 +160,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
161160
const callback = String(foundCallback)
162161
const response = Response.redirect(callback, statusCode)
163162

164-
return await noCache(response)
163+
return noCache(response)
165164
}
166165

167166
if (foundRoute?.method !== req.method) {
@@ -179,15 +178,15 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
179178
try {
180179
const fileContent = Bun.file(foundCallback)
181180

182-
return await new Response(fileContent, {
181+
return new Response(fileContent, {
183182
headers: {
184183
'Content-Type': 'text/html',
185184
'Access-Control-Allow-Origin': '*',
186185
'Access-Control-Allow-Headers': '*',
187186
},
188187
})
189188
} catch (error) {
190-
return await new Response('Error reading the HTML file', {
189+
return new Response('Error reading the HTML file', {
191190
status: 500,
192191
headers: {
193192
'Access-Control-Allow-Origin': '*',
@@ -198,7 +197,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
198197
}
199198

200199
if (isString(foundCallback))
201-
return await new Response(foundCallback, {
200+
return new Response(foundCallback, {
202201
headers: {
203202
'Content-Type': 'json',
204203
'Access-Control-Allow-Origin': '*',
@@ -210,7 +209,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
210209
if (isFunction(foundCallback)) {
211210
const result = foundCallback()
212211

213-
return await new Response(JSON.stringify(result), {
212+
return new Response(JSON.stringify(result), {
214213
status: 200,
215214
headers: {
216215
'Access-Control-Allow-Origin': '*',
@@ -223,7 +222,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
223222
if (foundCallback.status === 401) {
224223
const { status, ...rest } = foundCallback
225224

226-
return await new Response(JSON.stringify(rest), {
225+
return new Response(JSON.stringify(rest), {
227226
headers: {
228227
'Content-Type': 'json',
229228
'Access-Control-Allow-Origin': '*',
@@ -236,7 +235,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
236235
if (foundCallback.status === 403) {
237236
const { status, ...rest } = foundCallback
238237

239-
return await new Response(JSON.stringify(rest), {
238+
return new Response(JSON.stringify(rest), {
240239
headers: {
241240
'Content-Type': 'json',
242241
'Access-Control-Allow-Origin': '*',
@@ -249,7 +248,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
249248
if (foundCallback.status === 422) {
250249
const { status, ...rest } = foundCallback
251250

252-
return await new Response(JSON.stringify(rest), {
251+
return new Response(JSON.stringify(rest), {
253252
headers: {
254253
'Content-Type': 'json',
255254
'Access-Control-Allow-Origin': '*',
@@ -262,15 +261,15 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
262261
if (foundCallback.status === 500) {
263262
const { status, ...rest } = foundCallback
264263

265-
return await new Response(JSON.stringify(rest), {
264+
return new Response(JSON.stringify(rest), {
266265
headers: { 'Content-Type': 'json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*' },
267266
status: 500,
268267
})
269268
}
270269
}
271270

272271
if (isObject(foundCallback)) {
273-
return await new Response(JSON.stringify(foundCallback), {
272+
return new Response(JSON.stringify(foundCallback), {
274273
headers: {
275274
'Content-Type': 'json',
276275
'Access-Control-Allow-Origin': '*',
@@ -281,7 +280,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
281280
}
282281

283282
// If no known type matched, return a generic error.
284-
return await new Response('Unknown callback type.', {
283+
return new Response('Unknown callback type.', {
285284
headers: {
286285
'Content-Type': 'json',
287286
'Access-Control-Allow-Origin': '*',

storage/framework/server/build.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ async function main() {
4545
pkgName: 'server',
4646
})
4747

48-
const entrypoints = await glob([path.appPath('*.ts'), path.appPath('**/*.ts')])
49-
5048
const r2 = await build({
51-
entrypoints,
49+
entrypoints: await glob([path.appPath('*.ts'), path.appPath('**/*.ts')]),
5250
outdir: path.frameworkPath('server/dist'),
5351
format: 'esm',
5452
target: 'bun',
5553
sourcemap: 'linked',
5654
// minify: true,
5755
splitting: true,
56+
external: ['@swc/wasm'],
5857
})
5958

6059
// TODO: this is a bundler issue and those files should not need to be copied, and that's why we handle the cleanup here as well
@@ -72,6 +71,20 @@ async function main() {
7271
}
7372
}
7473

74+
// Process files in the ./dist folder
75+
// need to remove export `{ ENV_KEY, ENV_SECRET, fromEnv };` from whatever file that contains it in the dist/*
76+
// TODO: test later, potentially a bundler issue
77+
const distFiles = await glob([path.userServerPath('dist/*.js')])
78+
for (const file of distFiles) {
79+
let content = await fs.readFile(file, 'utf-8')
80+
if (content.includes('export { ENV_KEY, ENV_SECRET, fromEnv };')) {
81+
content = content.replace(/export { ENV_KEY, ENV_SECRET, fromEnv };/g, '')
82+
await fs.writeFile(file, content, 'utf-8')
83+
log.info(`Updated imports in ${file}`, { styled: false })
84+
break
85+
}
86+
}
87+
7588
await outro({
7689
dir: import.meta.dir,
7790
startTime: perf,

storage/framework/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"files": ["README.md", "dist", "src"],
4040
"scripts": {
4141
"dev": "./dev local",
42-
"dev:cloud": "docker run -d -p 3000:3000 stacks",
42+
"dev:cloud": "docker run -d -p 3000:3000 --name stacks-server --restart unless-stopped stacks",
4343
"build": "bun build.ts"
4444
},
4545
"dependencies": {

0 commit comments

Comments
 (0)