Skip to content

Commit

Permalink
perf: register api endpoint before static host
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 2, 2024
1 parent 079e5d4 commit 0b1360c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dev": "nuxi dev",
"prepare": "nuxi prepare",
"start": "node bin.mjs",
"prepublishOnly": "pnpm build",
"prepack": "pnpm build",
"lint": "nuxi prepare && eslint .",
"typecheck": "vue-tsc --noEmit"
},
Expand Down
14 changes: 5 additions & 9 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import { distDir } from './dirs'
export async function createHostServer() {
const app = connect()

console.log()

app.use(sirv(distDir, {
dev: true,
single: true,
}))

const ws = await createWsServer()

app.use('/api/payload.json', async (_req, res) => {
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(await ws.getData()))
})

const server = createServer(app)
app.use(sirv(distDir, {
dev: true,
single: true,
}))

return server
return createServer(app)
}

0 comments on commit 0b1360c

Please sign in to comment.