Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
document + expose a few more hardcoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
clux committed Aug 16, 2015
1 parent bc29ea4 commit 8a3bd6e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ before_script:
- export DATABASE_URL=postgres://postgres@localhost:5432/travis_linkr
- npm install bower -g
- bower install
- npm run init
- export LINKR_USER=clux
- export LINKR_EMAIL=h@x.io
- export LINKR_PASSWORD=heythere
- npm run setup
- make

after_script:
- npm run coveralls
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,48 @@

A link sharing site built on top of iojs, koa, postgresql, and polymer based web components using jwt for authentication.

## Usage
## Setup
Clone, generate rsa keys for jwt, set up database, and start:

```sh
git clone git@github.com:clux/linkr-app.git && cd linkr-app
# generate keys for jwt
openssl genrsa -out server.rsa 2048
openssl rsa -in server.rsa -pubout > server.rsa.pub
# install dependencies
bower install
npm install
npm run init
# create a postgres database, and expose its location:
export DATABASE_URL=postgres://localhost:5432/testdb
psql -c 'create database linkr;' -U postgres
export DATABASE_URL=postgres://localhost:5432/linkr
# initialize the database with a single administrator
export LINKR_USER=clux
export LINKR_EMAIL=h@x.io
export LINKR_PASSWORD=heythere
npm run setup
# build client app
make
# start the server
npm start
```

You may need to go via [node-gyp-install](https://npmjs.org/package/node-gyp-install) to install bcrypt.
You may need to go via [node-gyp-install](https://npmjs.org/package/node-gyp-install) to install bcrypt on certain versions of node.

## Logging in
Login with static username and password, then you have access to `/post` resources:
## Client App
[In development](#3).

## API
### Authentication
Authenticate with the credentials exported before calling `npm run init`:

```sh
curl -X POST -H "Content-Type: application/json" localhost:8000/login -d '{"username": "usr", "password": "pw"}'
curl -X GET -H "Authorization: Bearer $TOKEN" localhost:8000/post
curl -X POST -H "Content-Type: application/json" localhost:8000/login -d '{"username": "clux", "password": "heythere"}'
curl -X GET -H "Authorization: Bearer $TOKEN" localhost:8000/links
```

Any request other than `GET /` or `POST /login` will require the `Authorization: Bearer $TOKEN` header.

### Methods
### GET /links
### GET /links/:id
### POST /links
4 changes: 4 additions & 0 deletions development.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/bin/sh
export DATABASE_PASSWORD=arst
export DATABASE_URL=postgres://$USER:$DATABASE_PASSWORD@localhost:5432/linkr
export LINKR_USER=clux
export LINKR_EMAIL=h@x.io
export LINKR_PASSWORD=heythere
7 changes: 6 additions & 1 deletion init_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var bcrypt = require('co-bcrypt');
var db = require('./server/db');
var Link = db.Link;
var User = db.User;
var env = process.env;

if (!env.LINKR_USER || !env.LINKR_EMAIL || !env.LINKR_PASSWORD) {
throw new Error("Missing LINKR_{} environment variables");
}

var createUser = function *(username, email, password) {
var hash = yield bcrypt.hash(password, 10);
Expand All @@ -14,7 +19,7 @@ var createUser = function *(username, email, password) {
var main = function *() {
yield db.inst.sync({ force: true });

var u = yield createUser('clux', 'clux@x-pec.com', 'heythere');
var u = yield createUser(env.LINKR_USER, env.LINKR_EMAIL, env.LINKR_PASSWORD);
console.log('users now contain [%j]', u);

yield Link.bulkCreate([
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"main": "server",
"scripts": {
"init": "make && ./init_db.js",
"setup": "./init_db.js",
"start": "node app.js",
"test": "LINKR_SILENT=1 bndg test/*.test.js",
"testverbose": "bndg test/*.test.js",
Expand Down

0 comments on commit 8a3bd6e

Please sign in to comment.