-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: show default page if app has no public/ (#627)
- Loading branch information
Showing
10 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = locateWebroot | ||
|
||
var fs = require('fs') | ||
var pathModule = require('path') | ||
|
||
function locateWebroot (path) { | ||
if (fs.existsSync(path) && fs.statSync(path).isDirectory()) { | ||
return path | ||
} | ||
|
||
return pathModule.resolve(__dirname, '../public') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
var proxyquire = require('proxyquire').noCallThru() | ||
var simple = require('simple-mock') | ||
var test = require('tap').test | ||
var path = require('path') | ||
|
||
var fsMock = { | ||
'existsSync': simple.stub(), | ||
'statSync': simple.stub() | ||
} | ||
|
||
var statsMock = { | ||
'isDirectory': simple.stub() | ||
} | ||
|
||
test('webroot locator', function (group) { | ||
var webrootLocator = proxyquire('../../../cli/webroot-locator', { | ||
fs: fsMock | ||
}) | ||
|
||
group.afterEach(function (done) { | ||
fsMock.existsSync.actions = [] | ||
fsMock.existsSync.reset() | ||
fsMock.statSync.actions = [] | ||
fsMock.statSync.reset() | ||
statsMock.isDirectory.actions = [] | ||
statsMock.isDirectory.reset() | ||
done() | ||
}) | ||
|
||
group.test('will return the passed location if it exists and is a directory', function (t) { | ||
fsMock.existsSync.returnWith(true) | ||
fsMock.statSync.returnWith(statsMock) | ||
statsMock.isDirectory.returnWith(true) | ||
|
||
var configuredLocation = 'i-exist' | ||
var webroot = webrootLocator(configuredLocation) | ||
|
||
t.equal(fsMock.existsSync.lastCall.args[0], configuredLocation, 'path existence check') | ||
t.equal(statsMock.isDirectory.callCount, 1, 'path directory check') | ||
t.equal(webroot, configuredLocation, 'correct location returned') | ||
|
||
t.end() | ||
}) | ||
|
||
group.test('will return the default if the passed location exists but is not a directory', function (t) { | ||
fsMock.existsSync.returnWith(true) | ||
fsMock.statSync.returnWith(statsMock) | ||
statsMock.isDirectory.returnWith(false) | ||
|
||
var configuredLocation = 'im-a-file' | ||
var webroot = webrootLocator(configuredLocation) | ||
|
||
t.equal(fsMock.existsSync.lastCall.args[0], configuredLocation, 'path existence check') | ||
t.equal(statsMock.isDirectory.callCount, 1, 'path directory check') | ||
t.equal(webroot, path.resolve(__dirname, '../../../public'), 'correct location returned') | ||
|
||
t.end() | ||
}) | ||
|
||
group.test('will return the default if the passed location does not exist', function (t) { | ||
fsMock.existsSync.returnWith(false) | ||
|
||
var configuredLocation = 'i-cant-be-found' | ||
var webroot = webrootLocator(configuredLocation) | ||
|
||
t.equal(fsMock.existsSync.lastCall.args[0], configuredLocation, 'path existence check') | ||
t.equal(fsMock.statSync.callCount, 0, 'no stat check') | ||
t.equal(webroot, path.resolve(__dirname, '../../../public'), 'correct location returned') | ||
|
||
t.end() | ||
}) | ||
|
||
group.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var simple = require('simple-mock') | ||
var test = require('tap').test | ||
|
||
test('public', function (group) { | ||
var serverMock | ||
|
||
group.beforeEach(function (done) { | ||
serverMock = { | ||
register: simple.stub(), | ||
route: simple.stub(), | ||
ext: simple.stub() | ||
} | ||
|
||
require('../../../server/plugins/public').register(serverMock, { | ||
config: { | ||
paths: { | ||
public: 'my-custom-public-directory' | ||
} | ||
} | ||
}, function () { return }) | ||
|
||
done() | ||
}) | ||
|
||
group.test('configured public route', function (t) { | ||
t.equal(serverMock.route.callCount, 1, 'route was called') | ||
t.type(serverMock.route.lastCall.args[0], Array, 'route was called with an array') | ||
t.contains(serverMock.route.lastCall.args[0][0], | ||
{'handler': {'directory': {'path': /^my-custom-public-directory$/}}}, | ||
'route was configured to correct public directory') | ||
t.end() | ||
}) | ||
|
||
group.end() | ||
}) |