Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .eslintrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
**/dist
**/node_modules

# VSCode
.vscode

# Logs
logs
*.log
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint:staged
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "es5",
"useTabs": true,
"tabWidth": 4
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"orta.vscode-jest",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.formatOnPaste": true,
"editor.codeLens": true,
"editor.renderWhitespace": "all",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"eslint.format.enable": true,
"eslint.validate": ["javascript", "typescript"],
"jest.runMode": "on-demand",
}
60 changes: 60 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import { defineConfig, globalIgnores } from 'eslint/config';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

const defaultConfig = {
extends: compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
),
plugins: {
'@typescript-eslint': typescriptEslintEslintPlugin,
},
languageOptions: {
globals: {
...globals.node,
},
parser: tsParser,
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
project: 'tsconfig.json',
},
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
indent: ['error', 'tab'],
},
};

export default defineConfig([
globalIgnores(['**/.eslintrc.js']),
defaultConfig,
{
...defaultConfig,
files: ['**/*.spec.ts'],
rules: {
...defaultConfig.rules,
'@typescript-eslint/no-explicit-any': 'off',
},
},
]);
30 changes: 19 additions & 11 deletions lib/src/local-https-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { INestApplication } from '@nestjs/common';

/**
* **⚠ DISCLAIMER: For local development use only! ⚠**
*
*
* This is intended only for local development, testing, and troubleshooting.
* It is not recommended to use this in any production context or public-facing environment.
*
*
* @fires LocalHttpsProxy#listening when when the encapsulated {@link https.Server} successfully binds to a port and begins listening for connections.
* @fires LocalHttpsProxy#error for any error condition which occurs after initialization of the LocalHttpsProxy instance.
*/
export class LocalHttpsProxy extends EventEmitter implements LocalHttpsProxy {

export class LocalHttpsProxy extends EventEmitter implements ILocalHttpsProxy {
private readonly httpsProxyServer: https.Server;

/**
Expand All @@ -28,7 +27,7 @@ export class LocalHttpsProxy extends EventEmitter implements LocalHttpsProxy {
nestApp: INestApplication,
httpsOptions: SecureContextOptions,
errorCallback?: (error: Error) => void,
listeningCallback?: (port: number) => void
listeningCallback?: (port: number) => void,
) {
super();
if (!httpsOptions || !httpsOptions.cert || !httpsOptions.key)
Expand All @@ -46,15 +45,19 @@ export class LocalHttpsProxy extends EventEmitter implements LocalHttpsProxy {
* Start LocalHttpsProxy instance.
* @param listeningPort Optional: Port on which to listen for HTTPS connections, if not provided then an open port will be automatically assigned.
* @example <caption>Start a local HTTPS proxy listening on `0.0.0.0:43000`, proxying requests to your Nest app's HTTP server:</caption>
* const localHttpsProxy = new LocalHttpsProxy(app, httpsOptions);
* const localHttpsProxy = new LocalHttpsProxy(app, httpsOptions);
* localHttpsProxy.start(43000);
*/
public start(listeningPort?: number) {
if (!this.httpsProxyServer?.listening) {
this.httpsProxyServer.listen(listeningPort);
} else if (this.httpsProxyServer.listening) {
const address = this.httpsProxyServer.address() as AddressInfo;
this.onError(new Error(`Unable to start ${LocalHttpsProxy.name} on port ${listeningPort} because it is already listening on port ${address.port}`));
this.onError(
new Error(
`Unable to start ${LocalHttpsProxy.name} on port ${listeningPort} because it is already listening on port ${address.port}`,
),
);
}
}

Expand All @@ -72,7 +75,10 @@ export class LocalHttpsProxy extends EventEmitter implements LocalHttpsProxy {
* @param nestApp NestJS application instance.
* @returns New {@link https.Server} instance configured using {@link httpsOptions}.
*/
private initHttpsServer(httpsOptions: SecureContextOptions, nestApp: INestApplication): https.Server {
private initHttpsServer(
httpsOptions: SecureContextOptions,
nestApp: INestApplication,
): https.Server {
// Observe existing HTTP server in Nest app
const requestListener = this.getNestAppRequestListener(nestApp);

Expand All @@ -92,7 +98,9 @@ export class LocalHttpsProxy extends EventEmitter implements LocalHttpsProxy {
const adapter = nestApp.getHttpAdapter();
const listener = adapter?.getInstance()?.routing ?? adapter?.getInstance();
if (!listener)
throw new Error('Failed to derive HTTP server requestListener from Nest application');
throw new Error(
'Failed to derive HTTP server requestListener from Nest application',
);
return listener;
}

Expand All @@ -116,7 +124,7 @@ export class LocalHttpsProxy extends EventEmitter implements LocalHttpsProxy {
}
}

export declare interface LocalHttpsProxy {
export declare interface ILocalHttpsProxy {
/**
* Emitted when the encapsulated {@link https.Server} successfully binds to a port and begins listening for connections.
*/
Expand All @@ -126,4 +134,4 @@ export declare interface LocalHttpsProxy {
* Emitted for any error condition which occurs within the LocalHttpsProxy instance.
*/
on(event: 'error', listener: (error: Error) => void): this;
}
}
Loading