This repository was archived by the owner on Jul 8, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +69
-0
lines changed Expand file tree Collapse file tree 5 files changed +69
-0
lines changed Original file line number Diff line number Diff line change
1
+ web : npm start
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
1
+ require ( './src/server' ) . start ( function ( ) {
2
+ console . log ( 'server running' ) ;
3
+ } ) ;
You can’t perform that action at this time.
0 commit comments