Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 8cbcd61

Browse files
author
Abraham
committed
Added CORS setup on init creation of settings file from command line
1 parent fa4e729 commit 8cbcd61

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/cli/cli.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Cli {
3232
init(yargs) {
3333
this.setupConfig().then((options) => {
3434
options = Object.assign({}, this.defaultOptions, options);
35-
35+
3636
if (options.addClient) {
3737
let client = {
3838
appId: this.createAppId(),
@@ -44,6 +44,13 @@ export class Cli {
4444
console.log('key: ' + colors.magenta(client.key));
4545
}
4646

47+
if(options.corsAllow){
48+
options.apiOriginAllow.allowCors = true;
49+
options.apiOriginAllow.allowOrigin = options.allowOrigin;
50+
options.apiOriginAllow.allowMethods = options.allowMethods;
51+
options.apiOriginAllow.allowHeaders = options.allowHeaders;
52+
}
53+
4754
this.saveConfig(options).then(() => {
4855
console.log('Configuration file saved. Run ' + colors.magenta.bold('laravel-echo-server start') + ' to run server.');
4956

@@ -101,6 +108,32 @@ export class Cli {
101108
default: false,
102109
message: 'Do you want to generate a client ID/Key for HTTP API?',
103110
type: 'confirm'
111+
}, {
112+
name: 'corsAllow',
113+
default: false,
114+
message: 'Do you want to setup cross domain access to API? Useful for AJAX request to API on same domain different port.',
115+
type: 'confirm'
116+
},{
117+
name: 'allowOrigin',
118+
default: 'http://localhost',
119+
message: 'Enter the domain you want CORS access to:',
120+
when: function(options){
121+
return options.corsAllow == true;
122+
}
123+
},{
124+
name: 'allowMethods',
125+
default: 'GET, POST',
126+
message: 'Enter the CORS HTTP methods you want to allow:',
127+
when: function(options){
128+
return options.corsAllow == true;
129+
}
130+
},{
131+
name: 'allowHeaders',
132+
default: 'Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id',
133+
message: 'Enter the CORS headers you want to allow:',
134+
when: function(options){
135+
return options.corsAllow == true;
136+
}
104137
}
105138
]);
106139
}

0 commit comments

Comments
 (0)