Skip to content

Commit d561ca3

Browse files
authored
feat: improve core to support vercel
1 parent 24f4223 commit d561ca3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3195
-2114
lines changed
File renamed without changes.
File renamed without changes.

example/app-cloudflare/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"@photonjs/core": "workspace:",
1717
"typescript": "^5.8.3",
1818
"vite": "^6.3.5",
19-
"wrangler": "^4.15.1"
19+
"wrangler": "^4.19.1"
2020
},
2121
"dependencies": {
22-
"@universal-middleware/core": "^0.4.7",
22+
"@universal-middleware/core": "^0.4.9",
2323
"awesome-framework": "workspace:",
2424
"hono": "^4.7.8"
2525
}

example/app-cloudflare/testRun.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ function testRun(cmd: `pnpm run ${string}`) {
2525
expect(await response.text()).toBe('The API Route')
2626
})
2727

28+
test('/standalone', async () => {
29+
const response: Response = await fetch(`${getServerUrl()}/standalone`)
30+
expect(await response.text()).toBe('The /standalone Route')
31+
})
32+
2833
test('/bar', async () => {
2934
const response: Response = await fetch(`${getServerUrl()}/bar`)
3035
expect(await response.text()).toBe('bar')

example/app-cloudflare/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="@photonjs/core/api" />
1+
/// <reference types="@photonjs/core" />
22
/* The Vite plugin cloudflare() will be replaced by this:
33
import cloudflare from '@photonjs/cloudflare'
44
*/
@@ -10,7 +10,7 @@ export default defineConfig(({ mode }) => {
1010
return {
1111
// No photon server entry is defined, it will fallback to a virtual entry
1212
photon: {
13-
handlers: {
13+
entries: {
1414
// foo entry declares its route with `enhance` directly inside the file
1515
foo: 'src/middlewares/foo.ts',
1616
// bar entry route is declared here, and `enhance` is not used

example/app-hono-cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@photonjs/core": "workspace:",
1717
"typescript": "^5.8.3",
1818
"vite": "^6.3.5",
19-
"wrangler": "^4.15.1"
19+
"wrangler": "^4.19.1"
2020
},
2121
"dependencies": {
2222
"awesome-framework": "workspace:",

example/app-hono-cloudflare/server.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
// Will be moved to @photonjs/hono
22
import { apply, serve } from '@photonjs/core/hono'
3-
import awesomeFramework from 'awesome-framework/universal-middleware'
43
import { Hono } from 'hono'
54

65
async function startServer() {
76
const app = new Hono()
87

9-
apply(
10-
app,
11-
// Adds the framework's middlewares
12-
awesomeFramework,
13-
)
8+
// awesomeFramework will automatically be injected by apply
9+
apply(app)
1410

1511
return serve(app)
1612
}

example/app-hono-cloudflare/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference types="@photonjs/core/api" />
21
/* The Vite plugin cloudflare() will be replaced by this:
32
import cloudflare from '@photonjs/cloudflare'
43
*/

example/awesome-framework/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"@photonjs/core": "workspace:",
11-
"@universal-middleware/core": "^0.4.7",
11+
"@universal-middleware/core": "^0.4.9",
1212
"@universal-middleware/sirv": "^0.1.20"
1313
},
1414
"devDependencies": {
@@ -21,6 +21,7 @@
2121
"./entry-client": "./dist/entry-client.js",
2222
"./render": "./dist/render.js",
2323
"./vite": "./dist/vite/index.js",
24+
"./standalone": "./dist/photon/entries/standalone.js",
2425
"./universal-middleware": {
2526
"types": "./dist/photon/entries/prod.d.ts",
2627
"development": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { enhance } from '@universal-middleware/core'
2+
3+
const standaloneMiddleware = enhance(
4+
async () => {
5+
return new Response('The /standalone Route', {
6+
status: 200,
7+
headers: {
8+
'Content-Type': 'text/plain',
9+
},
10+
})
11+
},
12+
// enhance() adds meta data (a Universal Middleware in itself is just a Request => Response function)
13+
{
14+
name: 'awesome-framework:standalone',
15+
path: '/standalone',
16+
method: 'GET',
17+
},
18+
)
19+
20+
// This middleware will be used as a standalone handler, which means it is not included by `./universal-middleware` export
21+
export default standaloneMiddleware

0 commit comments

Comments
 (0)