Skip to content

Commit d42b3f9

Browse files
committed
feat: support dynamic origin
1 parent be8ec17 commit d42b3f9

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default defineNuxtConfig({
4747

4848
routeRules: {
4949
'/': { prerender: true },
50+
'/opensearch.xml': { isr: true },
5051
'/**': { isr: 60 },
5152
'/package/**': { isr: 60 },
5253
'/search': { isr: false, cache: false },

public/opensearch.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default defineEventHandler(async event => {
2+
const url = getRequestURL(event)
3+
const origin = url.origin
4+
return `
5+
<?xml version="1.0" encoding="UTF-8"?>
6+
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
7+
<ShortName>npm</ShortName>
8+
<Description>Search npm packages on npmx.dev</Description>
9+
<InputEncoding>UTF-8</InputEncoding>
10+
<Image width="16" height="16" type="image/svg+xml">${origin}/favicon.svg</Image>
11+
<Url type="text/html" template="${origin}/search?q={searchTerms}"/>
12+
<Url type="application/x-suggestions+json" template="${origin}/api/opensearch/suggestions?q={searchTerms}"/>
13+
<Url type="application/opensearchdescription+xml" rel="self" template="${origin}/opensearch.xml"/>
14+
</OpenSearchDescription>
15+
`.trim()
16+
})

0 commit comments

Comments
 (0)