Skip to content
/ hoodie Public
forked from hoodiehq/hoodie

🐶 A backend for Offline First applications

License

Notifications You must be signed in to change notification settings

kouryuu/hoodie

 
 

Repository files navigation

hoodie

A generic backend with a client API for Offline First applications

Build Status Coverage Status Dependency Status devDependency Status

Hacktoberfest 2016 Banner The Low-Profile Dog Hoodie Mascot
  <h2> Hallo <a href="https://hacktoberfest.digitalocean.com/">Hacktoberfest</a> Friends 🐶👋</h2>
  
  <p>
    We have some great issues prepared for you to work on, check out our <a href="https://github.com/hoodiehq/camp/issues">Hoodie Camp</a> repository :) If you have any questions or just want to say hi, please ping us <a href="https://twitter.com/hoodiehq">on Twitter</a> or join our <a href="http://hood.ie/chat/">Chat</a>. We are looking forward to meet you all! Happy hacktobering!  🙌💻
  </p>
</td>

Hoodie lets you build apps without thinking about the backend and makes sure that they work great independent from connectivity.

This is Hoodie’s main repository. It starts a server and serves the client API. Read more about how the Hoodie server works.

A good place to start is our Tracker App. You can play around with Hoodie’s APIs in the browser console and see how it works all together in its simple HTML & JavaScript code.

If you have any questions come say hi in our chat.

Setup

Hoodie is a Node.js package. You need Node Version 4 or higher and npm Version 2 or higher, check your installed version with node -v and npm -v.

First, create a folder and a package.json file

mkdir my-app
cd my-app
npm init -y

Next install hoodie and save it as dependency

npm install --save hoodie

Add a "start" script and set it to "hoodie" in your package.json. The result should look something like this

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "start": "hoodie",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "hoodie": "^24.0.0"
  }
}

There might be more properties and 24.0.0 will likely be a higher number, but that’s okay.

Now run npm start to start your Hoodie app.

You can find a more thorough description in our Getting Started Guide.

Usage

hoodie can be used as as CLI (Command Line Interface) or as hapi plugin. The options are slightly different, see below

CLI

Once you finished the setup, you can start your hoodie server with

npm start

To pass CLI options to Hoodie, you have to separate them with --, for example:

npm start -- --port=8090 --inMemory

Available CLI options are

option default description
--bindAddress '127.0.0.1' Address that Hoodie binds to
--data '.hoodie' Data path
--dbUrl If provided, uses external CouchDB. URL has to contain credentials.
--loglevel 'warn' One of: silent, error, warn, http, info, verbose, silly
-m, --inMemory false Whether to start the PouchDB Server in memory
--port 8080 Port-number to run the Hoodie App on
--public 'public' path to static assets
--url - Optional: external URL at which Hoodie Server is accessible (e.g. http://myhoodieapp.com)
-h, --help, --usage - Prints help and available options
-v, --version - Shows Hoodie version

Hoodie CLI is using rc for configuration, so the same options can be set with environment variables and config files. Environment variables are prefixed with hoodie_. Examples: hoodie_port=8090 or hoodie_inMemory=true. Configuration files can be in INI or JSON format and can be placed at different locations. Most commonly you would place a .hoodierc file in your app’s directory, and it can look like this

{
  port: 8090,
  inMemory: true
}

The priority of configuration:

  1. command line arguments
  2. Environment variables
  3. .hoodierc files
  4. Your app’s defaults form "hoodie" key in "package.json"
  5. Hoodie’s defaults as shown in table above

hapi plugin

You can load hoodie as hapi plugin to use it in your existing hapi application:

var Hapi = require('hapi')
var hoodie = require('hoodie').register

var server = new Hapi.Server()
server.connection({
  host: 'localhost',
  port: 8000
})

server.register({
  register: hoodie,
  options: { // pass options here
    inMemory: true,
    public: 'dist'
  }
}, function (error) {
  if (error) {
    throw error
  }

  server.start(function (error) {
    if (error) {
      throw error
    }

    console.log(('Server running at:', server.info.uri)
  })
})

The available options are

option default description
paths.data '.hoodie' Data path
paths.public 'public' Public path
db PouchDB options
inMemory false If set to true, configuration and other files will not be read from / written to the file system
client {} Hoodie Client options. client.url is set based on hapi’s server.info.host
account {} Hoodie Account Server options. account.admins, account.secret and account.usersDb are set based on db option above.
store {} Hoodie Store Server options. store.couchdb, store.PouchDB are set based on db option above. store.hooks.onPreAuth is set to bind user authentication for Hoodie Account to Hoodie Store.

Testing

Local setup

git clone https://github.com/hoodiehq/hoodie.git
cd hoodie
npm install

The hoodie test suite is run with npm test. You can read more about testing Hoodie.

You can start hoodie for itself using npm start. It will serve the contents of the public folder.

Backers

Become a backer and show your Hoodie support!

Official Sponsors

Show your support for Hoodie and help us sustain our inclusive community. We will publicly appreciate your support and are happy to get your word out, as long as it aligns with our Code of Conduct.

License

Apache 2.0

About

🐶 A backend for Offline First applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.3%
  • HTML 3.7%