-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
- '6' | ||
deploy: | ||
provider: heroku | ||
api_key: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Docker Setup | ||
============ | ||
|
||
Install Docker for Mac: https://www.docker.com/products/overview | ||
|
||
* `make` to build the base container (make each time you change the app) | ||
* `make run` to start it http://127.0.0.1:3000 | ||
* `docker-compose up` start both the mongo and site containers for API testing | ||
* `docker-compose build app` to build the app container for compose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM nodesource/xenial | ||
|
||
ENV PORT=3000 | ||
|
||
RUN mkdir /hacksi | ||
WORKDIR /hacksi | ||
|
||
COPY ./ /hacksi/ | ||
RUN cd /hacksi && npm install | ||
|
||
ENTRYPOINT cd /hacksi && node ./app.js | ||
EXPOSE 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
build: | ||
docker build . -t hacksi | ||
|
||
run: | ||
docker run --rm -it -p 3000:3000 hacksi | ||
|
||
debug: | ||
docker run --rm -it -p 3000:3000 --entrypoint /bin/bash hacksi | ||
|
||
all: build | ||
|
||
.PHONY: all build run debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '2' | ||
services: | ||
app: | ||
build: . | ||
environment: | ||
- MONGOLAB_URI=mongodb://mongodb/hacksi | ||
ports: | ||
- "3000:3000" | ||
depends_on: | ||
- mongodb | ||
mongodb: | ||
environment: | ||
- AUTH=no | ||
image: tutum/mongodb:3.2 | ||
ports: | ||
- "27017:27017" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var mongo = require('mongodb'); | ||
var joi = require('joi'); | ||
/* | ||
* We open and close this per request since we don't know how long between requests we will have. | ||
*/ | ||
|
||
exports.validate = { | ||
payload: { | ||
host: joi.string().min(4).required(), | ||
ip: joi.string().ip({ | ||
version: ['ipv4'], | ||
cidr: 'forbidden' | ||
}) | ||
} | ||
}; | ||
|
||
exports.post = function(req, res) { | ||
var pi = { | ||
_id: req.payload.host, | ||
host: req.payload.host, | ||
ip: req.payload.ip, | ||
stamp: Date.now(), | ||
from: req.headers['x-forwarded-for'] || req.info.remoteAddress | ||
}; | ||
mongo.connect(process.env.MONGOLAB_URI, function(err, db) { | ||
db.collection('pis').update({ _id: pi._id }, pi, { upsert: true }, function(err) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
db.close(); | ||
res(pi); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.get = function(req, res) { | ||
mongo.connect(process.env.MONGOLAB_URI, function(err, db) { | ||
db.collection('pis').find({ $query: {}, $orderby: { host: 1 }}).toArray(res); | ||
db.close(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters