Skip to content

Commit 7156be9

Browse files
authored
Merge pull request #19 from reslear/patch-1
feat: application/json
2 parents 091992e + 5e90074 commit 7156be9

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,38 @@ export default defineNuxtConfig({
170170
wellKnown: {
171171
contentUris: [
172172
{ path: 'apple-developer-merchantid-domain-association', content: 'merchantid' },
173-
{ path: 'content-uri.txt', content: 'content-uri' }
173+
{ path: 'content-uri.txt', content: 'content-uri' },
174+
175+
// iOS Universal Links example
176+
{
177+
path: 'apple-app-site-association',
178+
content: {
179+
applinks: {
180+
apps: [],
181+
details: [
182+
{
183+
appID: 'TEAMID.BUNDLEID',
184+
paths: ['*']
185+
}
186+
]
187+
}
188+
}
189+
},
190+
191+
// Android App Links example
192+
{
193+
path: 'assetlinks.json',
194+
content: [
195+
{
196+
relation: ['delegate_permission/common.handle_all_urls'],
197+
target: {
198+
namespace: 'android_app',
199+
package_name: 'com.netkosoft.beerswift',
200+
sha256_cert_fingerprints: ['43:12:D4:27:D7:C4:14...']
201+
}
202+
}
203+
]
204+
},
174205
]
175206
}
176207
})

src/runtime/server/middleware/content-uri.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineEventHandler, setHeader, sendError, H3Error } from 'h3'
22
import { ContentUriOptions } from '../../../types'
33
// @ts-ignore
44
import wellKnownOptions from '#well-known'
5+
import { isPlainObject } from '@vue/shared'
56

67
export default defineEventHandler((event) => {
78
const url = event.node.req.url
@@ -10,13 +11,20 @@ export default defineEventHandler((event) => {
1011
throw sendError(event, new H3Error('no url found in request'))
1112
}
1213

13-
setHeader(event, 'Content-Type', 'text/plain')
14-
1514
const path = url.split('/').pop()
15+
const contentUri = wellKnownOptions.contentUris.find(
16+
({ path: optionPath }) => optionPath === path
17+
)
18+
19+
setHeader(
20+
event,
21+
'Content-Type',
22+
isPlainObject(contentUri.content) ? 'application/json' : 'text/plain'
23+
)
1624

17-
return render(wellKnownOptions.contentUris.find(({ path: optionPath }) => optionPath === path))
25+
return render(contentUri)
1826
})
1927

20-
function render (options: ContentUriOptions) {
28+
function render(options: ContentUriOptions) {
2129
return options.content
2230
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export interface ChangePasswordOptions extends DefaultOptions {
2020

2121
export interface ContentUriOptions extends DefaultOptions {
2222
path: string;
23-
content: string;
23+
content: string | Record<any, any>;
2424
}

0 commit comments

Comments
 (0)