Skip to content

Commit

Permalink
WIP rename www/ to public/
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Mar 6, 2016
1 parent 8650d7c commit c7e7528
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -14,7 +14,7 @@

- providing a normalized [config](lib/config.js) for itself and all core components/plugins
- providing an API to interact with [databases](lib/database.js) to components/plugins
- starting and configuring a [hapi server](lib/hapi.js) that also serves [static components](lib/static.js) like hoodie-client and hoodie-admin-dashboard
- starting and configuring a [hapi server](lib/hapi.js) that also [serves static assets](lib/public.js) like hoodie-client and hoodie-admin-dashboard

The rest is handled by components like [hoodie-server-account](https://github.com/hoodiehq/hoodie-server-account), or [hoodie-server-store](https://github.com/hoodiehq/hoodie-server-store).

Expand All @@ -36,16 +36,16 @@ npm install

There are a few options to change the behaviour of `hoodie-server`.

option | default | description
------------- | ----------------------------- | -------------
path | process.cwd() | Project path
loglevel | 'warn' |
port | 8080 | Port-number to run the Hoddie App on
bindAddress | 127.0.0.1 | Address that Hoodie binds to
www | path.join(options.path, 'www') | WWW path
inMemory | false | Whether to start the PouchDB Server in memory
dbUrl | PouchDB Server | If provided does not start PouchDB Server and uses external CouchDB. Has to contain credentials.
data | path.join(options.path, 'data')| Data path
option | default | description
------------- | --------------------------------- | -------------
path | process.cwd() | Project path
loglevel | 'warn' |
port | 8080 | Port-number to run the Hoddie App on
bindAddress | 127.0.0.1 | Address that Hoodie binds to
public | path.join(options.path, 'public') | path to static assets
inMemory | false | Whether to start the PouchDB Server in memory
dbUrl | PouchDB Server | If provided does not start PouchDB Server and uses external CouchDB. Has to contain credentials.
data | path.join(options.path, 'data') | Data path

If that doesn’t make much sense just yet, don’t worry about it.

Expand Down
14 changes: 7 additions & 7 deletions lib/config.js
Expand Up @@ -16,23 +16,23 @@ module.exports = function (options) {
paths: {
data: options.data || path.join(projectPath, 'data'),
project: projectPath,
www: options.www || path.join(projectPath, 'www')
public: options.public || path.join(projectPath, 'public')
},
db: {},
admin: {},
account: options.account || {}
}

var wwwExists
var publicFolderExists
try {
wwwExists = fs.statSync(config.paths.www).isDirectory()
publicFolderExists = fs.statSync(config.paths.public).isDirectory()
} catch (err) {
wwwExists = false
publicFolderExists = false
}

if (!wwwExists) {
log.info('config', 'The "www" app path does not exist. Using default Hoodie app.')
config.paths.www = path.dirname(require.resolve('my-first-hoodie'))
if (!publicFolderExists) {
log.info('config', 'The "public" app path does not exist. Using default Hoodie app.')
config.paths.public = path.dirname(require.resolve('my-first-hoodie'))
}

_.each(_.values(config.paths), _.ary(mkdirp.sync, 1))
Expand Down
2 changes: 1 addition & 1 deletion lib/hapi.js
Expand Up @@ -21,7 +21,7 @@ module.exports = function (config, couchConfig, callback) {

var localPlugins = [
require('./http-log'),
require('./static')
require('./public')
].map(function (register) { return {options, register} })

var hoodieCorePlugins = [{
Expand Down
4 changes: 2 additions & 2 deletions lib/static.js → lib/public.js
Expand Up @@ -10,7 +10,7 @@ exports.register.attributes = {
}

function register (server, options, next) {
var app = path.join(options.config.paths.www, 'index.html')
var app = path.join(options.config.paths.public, 'index.html')
var dashboard = path.dirname(require.resolve('hoodie-admin-dashboard'))
var hoodieVersion
try {
Expand Down Expand Up @@ -38,7 +38,7 @@ function register (server, options, next) {
path: '/{p*}',
handler: {
directory: {
path: options.config.paths.www,
path: options.config.paths.public,
listing: false,
index: true
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/config-test.js
Expand Up @@ -17,7 +17,7 @@ test('config', function (t) {
tt.is(config.name, 'hoodie-server', 'exposes name from package.json')
tt.is(config.paths.project, cwd, 'uses cwd as project path')
tt.ok(config.paths.data.startsWith(cwd), 'derives data path from cwd')
tt.match(config.paths.www, /my-first-hoodie/, 'falls back to my-first-hoodie for www')
tt.match(config.paths.public, /my-first-hoodie/, 'falls back to my-first-hoodie for public')

tt.same(config.db, {}, 'uses empty db config')
tt.same(config.app, {
Expand Down Expand Up @@ -51,15 +51,15 @@ test('config', function (t) {
var config = getConfig({
path: 'project-path',
data: 'data-path',
www: 'www-path',
public: 'public-path',
bindAddress: 'hoodie-test',
port: 1337
})

tt.is(config.name, 'overwritten', 'exposes name from package.json')
tt.is(config.paths.project, 'project-path', 'uses path option as project path')
tt.is(config.paths.data, 'data-path', 'uses data option as data path')
tt.is(config.paths.www, 'www-path', 'uses www option as www path')
tt.is(config.paths.public, 'public-path', 'uses public option as public path')

tt.same(config.app, {
hostname: 'hoodie-test',
Expand Down

0 comments on commit c7e7528

Please sign in to comment.