Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.

Commit 01951f2

Browse files
committed
initial commit
1 parent 436bbcf commit 01951f2

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm start

config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = require('nconf')
2+
.env('__')
3+
.defaults({
4+
PORT: 8000,
5+
site: {
6+
host: 'www.valet.io'
7+
},
8+
ironmq: {
9+
queue_name: 'www-leads'
10+
}
11+
});

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "site-api",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "Tiny API for powering server side stuff on our website",
6+
"main": "index.js",
7+
"scripts": {
8+
"start": "node ./start.js",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/valet-io/site-api.git"
14+
},
15+
"author": "Ben Drucker <[email protected]> (http://www.bendrucker.me/)",
16+
"license": "MIT",
17+
"bugs": {
18+
"url": "https://github.com/valet-io/site-api/issues"
19+
},
20+
"homepage": "https://github.com/valet-io/site-api",
21+
"dependencies": {
22+
"bluebird": "~2.1.3",
23+
"hapi": "~6.0.2",
24+
"nconf": "~0.6.9"
25+
}
26+
}

src/server.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var hapi = require('hapi');
2+
var iron_mq = require('iron_mq');
3+
var Promise = require('bluebird');
4+
var config = require('../config');
5+
6+
var server = new hapi.Server('0.0.0.0', +config.get('PORT'), {
7+
cors: {
8+
origin: [config.get('site:host')]
9+
}
10+
});
11+
12+
var queue = Promise.promisifyAll(new iron_mq.Client(config.get('ironmq')));
13+
14+
server.route({
15+
method: 'POST',
16+
path: '/leads',
17+
handler: function (request, reply) {
18+
queue.postAsync(JSON.stringify(request.payload))
19+
.then(function () {
20+
reply().code(201);
21+
})
22+
.catch(function (err) {
23+
reply(hapi.error.internal('Could not add error to queue', err));
24+
});
25+
}
26+
});
27+
28+
module.exports = server;

start.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('./src/server').start(function () {
2+
console.log('server running');
3+
});

0 commit comments

Comments
 (0)