Skip to content

Commit 2876671

Browse files
committed
chore: comments/docs
1 parent 7b86a50 commit 2876671

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/cli/opts.start.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
"type": "string",
6666
"desc": "Choose which URL is auto-opened (local, external or tunnel), or provide a url"
6767
},
68+
"cors": {
69+
"type": "boolean",
70+
"desc": "Add Access Control headers to every request"
71+
},
6872
"config": {
6973
"type": "string",
7074
"alias": "c",

lib/default-config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ module.exports = {
105105
*/
106106
serveStatic: [],
107107

108+
/**
109+
* Options that are passed to the serve-static middleware
110+
* when you use the string[] syntax: eg: `serveStatic: ['./app']`. Please see
111+
* [serve-static](https://github.com/expressjs/serve-static) for details
112+
*
113+
* @property serveStaticOptions
114+
* @type Object
115+
* @since 1.17.0
116+
*/
117+
108118
/**
109119
* Enable https for localhost development. **Note** - this is not needed for proxy
110120
* option as it will be inferred from your target url.

lib/server/utils.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ var utils = {
7777
}
7878
];
7979

80+
/**
81+
* Add cors middleware to the front of the stack
82+
* if a user provided a 'cors' flag
83+
*/
8084
if (options.get("cors")) {
8185
defaultMiddlewares.unshift({
8286
id: "Browsersync CORS support",
@@ -85,8 +89,10 @@ var utils = {
8589
})
8690
}
8791

92+
/**
93+
* Add serve static middleware
94+
*/
8895
if (options.get("serveStatic")) {
89-
9096
var ssMiddlewares = utils.getServeStaticMiddlewares(options.get("serveStatic"), options.get("serveStaticOptions", Immutable.Map({})).toJS());
9197
var withErrors = ssMiddlewares.filter(function(x) { return x.get("errors").size > 0 });
9298
var withoutErrors = ssMiddlewares.filter(function(x) { return x.get("errors").size === 0 });
@@ -172,6 +178,11 @@ var utils = {
172178
next();
173179
}
174180
},
181+
/**
182+
* @param ssOption
183+
* @param serveStaticOptions
184+
* @returns {*}
185+
*/
175186
getServeStaticMiddlewares: function (ssOption, serveStaticOptions) {
176187

177188
return ssOption.map(function (dir, i) {
@@ -212,10 +223,20 @@ var utils = {
212223
}]
213224
})
214225
});
226+
227+
/**
228+
* @param {string} x
229+
* @returns {string}
230+
*/
215231
function getRoute (x) {
216232
if (x === "") return "";
217233
return x[0] === "/" ? x : "/" + x;
218234
}
235+
236+
/**
237+
* @param dir
238+
* @returns {Map}
239+
*/
219240
function getFromString(dir) {
220241
return fromJS({
221242
items: [
@@ -227,6 +248,11 @@ var utils = {
227248
errors: []
228249
})
229250
}
251+
252+
/**
253+
* @param dir
254+
* @returns {Map}
255+
*/
230256
function getFromMap(dir) {
231257

232258
var ssOptions = (function () {

0 commit comments

Comments
 (0)