Skip to content

Commit

Permalink
feat(web): expose cache, compression options for file-server (#16546)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Diehl <[email protected]>
  • Loading branch information
jaysoo and rpd10 authored Apr 25, 2023
1 parent f0295fa commit ae8c47b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs/generated/packages/web/executors/file-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@
"type": "boolean",
"description": "Enable CORS",
"default": true
},
"gzip": {
"type": "boolean",
"description": "Enable gzip compression",
"default": false
},
"brotli": {
"type": "boolean",
"description": "Enable brotli compression",
"default": false
},
"cacheSeconds": {
"type": "number",
"description": "Set cache time (in seconds) for cache-control max-age header. To disable caching, use -1. Caching defaults to disabled.",
"default": -1
}
},
"additionalProperties": false,
Expand Down
8 changes: 7 additions & 1 deletion packages/web/src/executors/file-server/file-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { readModulePackageJson } from 'nx/src/utils/package-json';
const pmCmd = platform() === 'win32' ? `npx.cmd` : 'npx';

function getHttpServerArgs(options: Schema) {
const args = ['-c-1'];
const args = [`-c${options.cacheSeconds}`];

if (options.cors) {
args.push(`--cors`);
Expand All @@ -43,6 +43,12 @@ function getHttpServerArgs(options: Schema) {
if (options.proxyUrl) {
args.push(`-P=${options.proxyUrl}`);
}
if (options.gzip) {
args.push('-g');
}
if (options.brotli) {
args.push('-b');
}

if (options.proxyOptions) {
Object.keys(options.proxyOptions).forEach((key) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/executors/file-server/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export interface Schema {
spa: boolean;
staticFilePath?: string;
cors?: boolean;
gzip?: boolean;
brotli?: boolean;
cacheSeconds?: number;
}
15 changes: 15 additions & 0 deletions packages/web/src/executors/file-server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@
"type": "boolean",
"description": "Enable CORS",
"default": true
},
"gzip": {
"type": "boolean",
"description": "Enable gzip compression",
"default": false
},
"brotli": {
"type": "boolean",
"description": "Enable brotli compression",
"default": false
},
"cacheSeconds": {
"type": "number",
"description": "Set cache time (in seconds) for cache-control max-age header. To disable caching, use -1. Caching defaults to disabled.",
"default": -1
}
},
"additionalProperties": false,
Expand Down

1 comment on commit ae8c47b

@vercel
Copy link

@vercel vercel bot commented on ae8c47b Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.