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
14 changes: 12 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ module.exports = class Config {
watchOptions: Joi.object().default().keys({
ignored: Joi.array().default('node_modules')
}),
server: Joi.object().default({}),
server: Joi.default({})
Copy link
Member

Choose a reason for hiding this comment

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

How come object came out here?

Copy link
Member

Choose a reason for hiding this comment

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

I guess because it can be false now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we need to default to empty object before we check Joi.exist('proxy'), otherwise that check passess, the server is set to {} afterwards and then browser-sync will fail the proxy option (Server must be false with proxy option…)

Copy link
Member

Choose a reason for hiding this comment

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

👍

.when('proxy', { is: Joi.exist(),
then: Joi.required().only(false),
otherwise: Joi.object()
}),
proxy: Joi.alternatives().try(
Joi.object().keys({ target: Joi.string().required() }),
Joi.string()
).optional(),
port: Joi.number().default(1111),
middleware: Joi.array().default([]),
logLevel: Joi.string().default('silent'),
Expand All @@ -83,7 +91,9 @@ module.exports = class Config {
let res = validation.value

// Joi can't handle defaulting this, so we do it manually
res.server.server.baseDir = res.outputDir.replace(res.root, '')
if (res.server.server) {
res.server.server.baseDir = res.outputDir.replace(res.root, '')
}

// add cleanUrls middleware to browserSync if cleanUrls === true
if (res.cleanUrls) {
Expand Down
4 changes: 4 additions & 0 deletions test/config_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ test('config errors', (t) => {
'ValidationError: child "babel" fails because ["babel" must be an object]')
t.throws(() => { new Spike({ root: 'foo', entry: ['foo', 'bar'] }) }, // eslint-disable-line
'ValidationError: child "entry" fails because ["entry" must be an object]')
t.throws(() => { new Spike({ root: 'foo', server: {server: false} }) }, // eslint-disable-line
'ValidationError: child "server" fails because [child "server" fails because ["server" must be an object]]')
t.throws(() => { new Spike({ root: 'foo', server: {server: {}, proxy: 'http://localhost:1234/'} }) }, // eslint-disable-line
'ValidationError: child "server" fails because [child "server" fails because ["server" must be one of [false]]]')
})