Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint rework #2

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
node_modules

# Swap files
*.swp
38 changes: 38 additions & 0 deletions bin/data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions bin/server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions lib/data.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'
#
# CloudMine, Inc
# 2015
#

goodApiKey = (req) ->
headers = Object.keys req.headers
"x-cloudmine-apikey" in headers

_empty = (obj) ->
Object.keys(obj).length == 0

addData = (req) ->
payload = if req.payload? then req.payload else {}
req.data = {
apikey: req.headers["x-cloudmine-apikey"]
request: {
method: req.method.toUpperCase()
}
input: payload
params: if _empty(req.query) then payload else req.query
}

if not _empty(payload) then req.data.request["content-type"] = req.mime

module.exports = { add: addData, goodApiKey: goodApiKey }
5 changes: 4 additions & 1 deletion lib/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Hapi = require 'hapi'
{badRequest} = require 'boom'
join = require('path').join
data = require './data'

class Server

Expand Down Expand Up @@ -38,9 +39,11 @@ class Server
_setupRoutes: ->
@server.route
method: ['PUT', 'POST', 'GET']
path: '/code/{name}'
path: '/v1/app/{appid}/run/{name}'
handler: (req, reply)=>
snippet = @requiredFile[req.params.name]
return reply({errors: ["API Key invalid"]}) unless data.goodApiKey req
data.add(req)
return reply(badRequest('Snippet Not Found!')) unless snippet
snippet(req, reply)

Expand Down