Skip to content

Commit 92584ac

Browse files
committed
🎉 feat: merge main
1 parent 544a64b commit 92584ac

14 files changed

+43
-59
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.5.0 -14 May 2023
2+
Improvement:
3+
- Add support for Elysia 0.5.0-beta.2
4+
15
# 0.3.0 - 17 Mar 2023
26
Improvement:
37
- Add support for Elysia 0.3.0

bun.lockb

123 Bytes
Binary file not shown.

example/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { Elysia } from 'elysia'
22
import cors from '../src/index'
33

44
const app = new Elysia()
5-
.use(
6-
cors({
7-
origin: /\*.saltyaom.com$/
8-
})
9-
)
10-
.get('/', () => 'Hi')
5+
.use(cors({
6+
maxAge: 5
7+
}))
8+
.get('/', () => ({
9+
hello: 'world'
10+
}))
11+
.post('/', () => 'Hi')
1112
.listen(8080)

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/cors",
3-
"version": "0.3.0",
3+
"version": "0.5.0-rc.0",
44
"description": "Plugin for Elysia that for Cross Origin Requests (CORs)",
55
"author": {
66
"name": "saltyAom",
@@ -34,12 +34,12 @@
3434
"devDependencies": {
3535
"@types/node": "^18.11.7",
3636
"bun-types": "^0.5.7",
37-
"elysia": "^0.3.0",
37+
"elysia": "0.5.0-beta.2",
3838
"eslint": "^8.26.0",
3939
"rimraf": "^3.0.2",
4040
"typescript": "^4.9.4"
4141
},
4242
"peerDependencies": {
43-
"elysia": ">= 0.3.0"
43+
"elysia": ">= 0.5.0-beta.2"
4444
}
4545
}

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,24 @@ export const cors =
275275
})
276276
})
277277

278-
return app.onRequest((context) => {
279-
handleOrigin(context.set, context.request)
280-
handleMethod(context.set)
278+
return app.onRequest(({ set, request }) => {
279+
handleOrigin(set, request)
280+
handleMethod(set)
281281

282282
if (allowedHeaders.length)
283-
context.set.headers['Access-Control-Allow-Headers'] =
283+
set.headers['Access-Control-Allow-Headers'] =
284284
typeof allowedHeaders === 'string'
285285
? allowedHeaders
286286
: allowedHeaders.join(', ')
287287

288288
if (exposedHeaders.length)
289-
context.set.headers['Access-Control-Exposed-Headers'] =
289+
set.headers['Access-Control-Exposed-Headers'] =
290290
typeof exposedHeaders === 'string'
291291
? exposedHeaders
292292
: exposedHeaders.join(', ')
293293

294294
if (credentials)
295-
context.set.headers['Access-Control-Allow-Credentials'] = 'true'
295+
set.headers['Access-Control-Allow-Credentials'] = 'true'
296296
})
297297
}
298298

test/allow-headers.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import { Elysia } from 'elysia'
22
import { cors } from '../src'
33

44
import { describe, expect, it } from 'bun:test'
5-
6-
const req = (path: string, headers?: Record<string, string>) =>
7-
new Request(path, {
8-
headers
9-
})
5+
import { req } from './utils'
106

117
describe('Allowed Headers', () => {
128
it('Accept single header', async () => {

test/credentials.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import { Elysia } from 'elysia'
22
import { cors } from '../src'
33

44
import { describe, expect, it } from 'bun:test'
5-
6-
const req = (path: string, headers?: Record<string, string>) =>
7-
new Request(path, {
8-
headers
9-
})
5+
import { req } from './utils'
106

117
describe('Credentials', () => {
128
it('Allow credential', async () => {

test/exposed-header.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import { Elysia } from 'elysia'
22
import { cors } from '../src'
33

44
import { describe, expect, it } from 'bun:test'
5-
6-
const req = (path: string, headers?: Record<string, string>) =>
7-
new Request(path, {
8-
headers
9-
})
5+
import { req } from './utils'
106

117
describe('Exposed Headers', () => {
128
it('Expose single header', async () => {

test/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { Elysia } from 'elysia'
22
import { cors } from '../src'
33

44
import { describe, expect, it } from 'bun:test'
5-
6-
const req = (path: string) => new Request(path)
5+
import { req } from './utils'
76

87
describe('CORS', () => {
98
it('Accept all CORS by default', async () => {

test/max-age.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { Elysia } from 'elysia'
22
import { cors } from '../src'
33

44
import { describe, expect, it } from 'bun:test'
5-
6-
const req = (path: string, headers?: Record<string, string>) =>
7-
new Request(`http://localhost${path}`, {
8-
method: 'OPTIONS',
9-
headers
10-
})
5+
import { preflight, req } from './utils'
116

127
describe('Max Age', () => {
138
it('Set maxage', async () => {
@@ -17,7 +12,7 @@ describe('Max Age', () => {
1712
})
1813
)
1914

20-
const res = await app.handle(req('/'))
15+
const res = await app.handle(preflight('/'))
2116
expect(res.headers.get('Access-Control-Max-Age')).toBe('5')
2217
})
2318

@@ -28,7 +23,7 @@ describe('Max Age', () => {
2823
})
2924
)
3025

31-
const res = await app.handle(req('/'))
26+
const res = await app.handle(preflight('/'))
3227
expect(res.headers.get('Access-Control-Max-Age')).toBe(null)
3328
})
3429
})

0 commit comments

Comments
 (0)