Browse Source

Basic functionality now works

Fixing-CORS-crash
BinHong Lee 7 years ago
parent
commit
8267064a35
3 changed files with 50 additions and 6 deletions
  1. +2
    -0
      .gitignore
  2. +43
    -5
      index.js
  3. +5
    -1
      package.json

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
node_modules
package-lock.json

+ 43
- 5
index.js View File

@@ -1,6 +1,44 @@
var http = require('http')
var bodyParser = require('body-parser')
var express = require('express')

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'})
response.end('Breakup\n')
}).listen(process.env.PORT)
var app = express()
var input

app.use(bodyParser.json({
limit: '100mb',
type: 'application/json'
}))
app.get('/help', function (req, res) {
res.send('https://github.com/binhonglee/Breakups')
})
app.post('/total', function (req, res) {
input = req.body
var toReturn = { 'total': 0 }
toReturn.total = total(input.users)
res.json(toReturn)
})
app.post('/perPerson', function (req, res) {
input = req.body
var toReturn = { 'perPerson': 0 }
toReturn.perPerson = (total(input.users)) / input.users.length
res.json(toReturn)
})
app.post('/oweChart', function (req, res) {
input = req.body
var perPerson = total(input.users) / input.users.length
for (var i = 0; i < input.users.length; i++) {
input.users[i].amount -= perPerson
}
res.json(input)
})
// app.listen(3000)
app.listen(process.env.PORT)

function total (input) {
var total = 0
for (var i = 0; i < input.length; i++) {
total += input[i].amount
}

return total
}

+ 5
- 1
package.json View File

@@ -8,5 +8,9 @@
"start": "node index.js"
},
"author": "",
"license": "MIT"
"license": "MIT",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2"
}
}

Loading…
Cancel
Save