Skip to content

Commit

Permalink
feat(nx-plugin): add proxy config support to file-server executor
Browse files Browse the repository at this point in the history
  • Loading branch information
austinhappel committed Mar 9, 2022
1 parent fd64546 commit 7b53a53
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/web/src/executors/file-server/file-server.impl.ts
@@ -1,12 +1,12 @@
import { exec, execSync } from 'child_process';
import { ExecutorContext, joinPathFragments } from '@nrwl/devkit';
import ignore from 'ignore';
import { workspaceLayout } from '@nrwl/workspace/src/core/file-utils';
import { exec, execSync } from 'child_process';
import { watch } from 'chokidar';
import { readFileSync } from 'fs';
import ignore from 'ignore';
import { Schema } from './schema';
import { watch } from 'chokidar';
import { workspaceLayout } from '@nrwl/workspace/src/core/file-utils';

function getHttpServerArgs(options: Schema) {
function getHttpServerArgs(options: Schema, context: ExecutorContext) {
const args = ['-c-1'];
if (options.port) {
args.push(`-p ${options.port}`);
Expand All @@ -26,6 +26,12 @@ function getHttpServerArgs(options: Schema) {
if (options.proxyUrl) {
args.push(`-P ${options.proxyUrl}`);
}

if (options.proxyOptions) {
Object.keys(options.proxyOptions).forEach((key) => {
args.push(`--proxy-options.${key}`, options.proxyOptions[key]);
});
}
return args;
}

Expand Down Expand Up @@ -123,7 +129,7 @@ export default async function* fileServerExecutor(
run();

const outputPath = getBuildTargetOutputPath(options, context);
const args = getHttpServerArgs(options);
const args = getHttpServerArgs(options, context);

const serve = exec(`npx http-server ${outputPath} ${args.join(' ')}`, {
cwd: context.root,
Expand Down
29 changes: 29 additions & 0 deletions packages/web/src/executors/file-server/schema.d.ts
Expand Up @@ -9,4 +9,33 @@ export interface Schema {
parallel: boolean;
maxParallel?: number;
withDeps: boolean;
proxyOptions?: ProxyOptions;
}

export interface ProxyOptions {
// target: string; Used by http-server internally
// changeOrigin: boolean; Used by http-server internally
// ssl: object; Use Schema ssl/sslKey/sslCert instead
// toProxy: boolean; Http-server does not proxy to another proxy
agent?: object;
forward?: string;
secure?: boolean;
ws?: boolean;
xfwd?: boolean;
prependPath?: boolean;
ignorePath?: boolean;
localAddress?: string;
changeOrigin?: boolean;
preserveHeaderKeyCase?: boolean;
auth?: string;
hostRewrite?: string;
autoRewrite?: boolean;
protocolRewrite?: string;
cookieDomainRewrite?: boolean | string | object;
cookiePathRewrite?: boolean | string | object;
headers?: object;
proxyTimeout?: number;
followRedirects?: boolean;
selfHandleResponse?: boolean;
buffer?: Buffer;
}
12 changes: 12 additions & 0 deletions packages/web/src/executors/file-server/schema.json
Expand Up @@ -48,6 +48,18 @@
"proxyUrl": {
"type": "string",
"description": "URL to proxy unhandled requests to."
},
"proxyOptions": {
"type": "object",
"description": "Options for the proxy used by http-server",
"default": {},
"properties": {
"secure": {
"type": "boolean",
"default": false
}
},
"additionalProperties": true
}
},
"additionalProperties": false,
Expand Down

0 comments on commit 7b53a53

Please sign in to comment.