MCPcopy Index your code
hub / github.com/tiann/hapi / sendHookRequest

Function sendHookRequest

cli/src/opencode/utils/startOpencodeHookServer.test.ts:5–40  ·  view source on GitHub ↗
(
    port: number,
    body: string,
    token?: string
)

Source from the content-addressed store, hash-verified

3import { startOpencodeHookServer } from './startOpencodeHookServer'
4
5const sendHookRequest = async (
6 port: number,
7 body: string,
8 token?: string
9): Promise<{ statusCode?: number; body: string }> => {
10 return await new Promise((resolve, reject) => {
11 const headers: Record<string, string | number> = {
12 'Content-Type': 'application/json',
13 'Content-Length': Buffer.byteLength(body)
14 }
15 if (token) {
16 headers['x-hapi-hook-token'] = token
17 }
18
19 const req = request({
20 host: '127.0.0.1',
21 port,
22 path: '/hook/opencode',
23 method: 'POST',
24 headers
25 }, (res) => {
26 const chunks: Buffer[] = []
27 res.on('data', (chunk) => chunks.push(chunk as Buffer))
28 res.on('error', reject)
29 res.on('end', () => {
30 resolve({
31 statusCode: res.statusCode,
32 body: Buffer.concat(chunks).toString('utf-8')
33 })
34 })
35 })
36
37 req.on('error', reject)
38 req.end(body)
39 })
40}
41
42describe('startOpencodeHookServer', () => {
43 it('forwards hook payload to callback', async () => {

Callers 1

Calls 3

endMethod · 0.80
onMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected