Skip to content

Commit a53bf1f

Browse files
committed
Added typescript definitions
1 parent fdc00a0 commit a53bf1f

5 files changed

Lines changed: 1074 additions & 9 deletions

File tree

nodejs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backloop.dev",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"description": "Local HTTPS development with *.backloop.dev pointing to localhost and SSL certificates",
55
"keywords": [
66
"SSL",
@@ -28,12 +28,14 @@
2828
"author": "Perki (https://backloop.dev)",
2929
"exports": {
3030
".": {
31+
"types": "./src/index.d.ts",
3132
"import": "./src/index.mjs",
3233
"require": "./src/index.js"
3334
}
3435
},
3536
"main": "src/index.js",
3637
"module": "src/index.mjs",
38+
"types": "src/index.d.ts",
3739
"bin": {
3840
"backloop.dev": "bin/webserver.js",
3941
"backloop.dev-proxy": "bin/proxy.js",

nodejs/src/index.d.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @license
3+
* [BSD-3-Clause](https://github.com/perki/backloop.dev/blob/main/LICENSE)
4+
*/
5+
6+
/**
7+
* HTTPS options for use with Node.js https.createServer()
8+
*/
9+
export interface HttpsOptions {
10+
/** Private key in PEM format */
11+
key: string;
12+
/** Certificate in PEM format */
13+
cert: string;
14+
/** Certificate Authority chain in PEM format */
15+
ca: string;
16+
}
17+
18+
/**
19+
* Callback for httpsOptionsAsync
20+
*/
21+
export type HttpsOptionsCallback = (error: Error | null, options?: HttpsOptions) => void;
22+
23+
/**
24+
* Synchronously returns HTTPS options for backloop.dev certificates.
25+
* If certificates are missing or expired, attempts an automatic update
26+
* and exits the process.
27+
*
28+
* @returns HTTPS options object with key, cert, and ca properties
29+
*
30+
* @example
31+
* ```js
32+
* const https = require('https');
33+
* const { httpsOptions } = require('backloop.dev');
34+
*
35+
* https.createServer(httpsOptions(), app).listen(443);
36+
* ```
37+
*/
38+
export function httpsOptions(): HttpsOptions;
39+
40+
/**
41+
* Asynchronously retrieves HTTPS options using a callback.
42+
* Updates certificates if needed before returning.
43+
*
44+
* @param done - Callback called with (error, options)
45+
*
46+
* @example
47+
* ```js
48+
* const { httpsOptionsAsync } = require('backloop.dev');
49+
*
50+
* httpsOptionsAsync((err, options) => {
51+
* if (err) throw err;
52+
* https.createServer(options, app).listen(443);
53+
* });
54+
* ```
55+
*/
56+
export function httpsOptionsAsync(done: HttpsOptionsCallback): void;
57+
58+
/**
59+
* Asynchronously retrieves HTTPS options using a Promise.
60+
* Updates certificates if needed before returning.
61+
*
62+
* @returns Promise resolving to HTTPS options
63+
*
64+
* @example
65+
* ```js
66+
* const { httpsOptionsPromise } = require('backloop.dev');
67+
*
68+
* const options = await httpsOptionsPromise();
69+
* https.createServer(options, app).listen(443);
70+
* ```
71+
*/
72+
export function httpsOptionsPromise(): Promise<HttpsOptions>;

vitejs/index.d.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
export default backloop;
1+
/**
2+
* Vite plugin for backloop.dev HTTPS local development
3+
* @param hostname - Subdomain to use (e.g., 'myapp' becomes myapp.backloop.dev)
4+
* @param port - Optional port number for the dev server
5+
* @returns Vite plugin configuration
6+
*/
27
declare function backloop(hostname?: string, port?: number): {
3-
name: string;
4-
apply: ConfigEnv;
5-
config(options: UserConfigExport): void;
6-
};
8+
name: string;
9+
apply: 'serve';
10+
config(config: Record<string, unknown>): void;
11+
};
12+
13+
export default backloop;

0 commit comments

Comments
 (0)