• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sajov / feathers-solr / 10805319139

11 Sep 2024 05:04AM UTC coverage: 100.0%. Remained the same
10805319139

push

github

web-flow
Bump serve-static and express (#300)

Bumps [serve-static](https://github.com/expressjs/serve-static) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.

Updates `serve-static` from 1.15.0 to 1.16.0
- [Release notes](https://github.com/expressjs/serve-static/releases)
- [Changelog](https://github.com/expressjs/serve-static/blob/master/HISTORY.md)
- [Commits](https://github.com/expressjs/serve-static/compare/v1.15.0...1.16.0)

Updates `express` from 4.19.2 to 4.20.0
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/master/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.19.2...4.20.0)

---
updated-dependencies:
- dependency-name: serve-static
  dependency-type: indirect
- dependency-name: express
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

119 of 119 branches covered (100.0%)

149 of 149 relevant lines covered (100.0%)

189.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/httpClient.ts
1
import http from 'http';
1✔
2
import https from 'https';
1✔
3

4
export interface httpClientOptions {
5
  hostname: string;
6
  username?: string;
7
  password?: string;
8
}
9

10
interface MethodOptions {
11
  params?: any;
12
  data?: any;
13
}
14

15
export interface HttpClient {
16
  get: (resource: string, options: MethodOptions) => Promise<any>;
17
  post: (resource: string, options: MethodOptions) => Promise<any>;
18
}
19

20
export interface RequestOptions {
21
  url: string;
22
  requestOptions?: http.RequestOptions | https.RequestOptions;
23
  data?: any;
24
  logger?: any;
25
}
26

27
const request = async (options: RequestOptions) => {
1✔
28
  const { url, data, requestOptions, logger } = options;
683✔
29
  const { method } = requestOptions;
683✔
30
  const { protocol } = new URL(url);
683✔
31
  const transport = protocol === 'https:' ? https : http;
683✔
32

33
  logger({url, data});
683✔
34
  return new Promise((resolve, reject): void => {
683✔
35
    const request = transport.request(url,
683✔
36
      {
37
        ...requestOptions,
38
        headers: method === 'GET' ?
683✔
39
          { 'Content-Type': 'application/json' } :
40
          { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) }
41
      },
42
      (res: any): void => {
43
        if (res.statusCode < 200 || res.statusCode > 299) {
682✔
44
          logger({statusCode: res.statusCode});
1✔
45
          return reject(new Error(`HTTP status code ${res.statusCode}`));
1✔
46
        }
47

48
        const body: any = [];
681✔
49
        res.on('data', (chunk: any) => body.push(chunk));
699✔
50
        res.on('end', () => resolve(JSON.parse(Buffer.concat(body).toString('utf8'))));
681✔
51
      }
52
    );
53

54
    request.on('error', (err: Error) => {
683✔
55
      logger({err});
1✔
56
      reject(err);
1✔
57
    });
58

59
    request.on('timeout', () => {
683✔
60
      request.destroy();
1✔
61
      logger('timeout');
1✔
62
      reject(new Error('timed out'));
1✔
63
    });
64

65
    if (data) request.write(data);
683✔
66

67
    request.end();
683✔
68
  })
69
}
70

71
export const httpClient = (hostname: string, requestOptions: http.RequestOptions = {}, logger: any = () => {}): HttpClient => {
1✔
72

73
  function getUrl({ resource, params }: { resource: string; params: any; }): string {
74
    const url = `${hostname}${resource}`;
683✔
75
    return !params || !Object.keys(params).length ? url : `${url}?${new URLSearchParams(params)}`;
683✔
76
  }
77

78
  async function get(resource: string, options: MethodOptions): Promise<unknown> {
79
    const { params } = options;
14✔
80
    return await request({
14✔
81
      url: getUrl({ resource, params }),
82
      requestOptions: {
83
        ...requestOptions,
84
        method: 'GET'
85
      },
86
      logger
87
    });
88
  }
89

90
  async function post(resource: string, options: MethodOptions): Promise<unknown> {
91
    const { params, data } = options;
669✔
92
    return await request({
669✔
93
      url: getUrl({ resource, params }),
94
      data: JSON.stringify(data),
95
      requestOptions: {
96
        ...requestOptions,
97
        method: 'POST'
98
      },
99
      logger
100
    });
101
  }
102

103
  return {
21✔
104
    get,
105
    post
106
  }
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc