Skip to content

Commit

Permalink
remove commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
noogen committed Nov 25, 2018
1 parent f3162ab commit 596e1a6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:10
LABEL maintainer="noogen <[email protected]>"
ENV NPM_CONFIG_LOGLEVEL=warn \
LAMBDA_FORM_VERSION=1.2.2
LAMBDA_FORM_VERSION=1.2.3
EXPOSE 5000

RUN apt-get update && apt-get upgrade -y \
Expand Down
15 changes: 8 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require("@babel/register")
require('@babel/register')

const post = require('./lib/postHandler')
const http = require('http')
const URL = require('url')
const resp = require('./lib/response').default
const post = require('./lib/postHandler')
const http = require('http')
const URL = require('url')
const resp = require('./lib/response').default
const debug = require('debug')('lambda-form')

http.createServer((req, res) => {
if (req.method !== 'POST') {
Expand All @@ -22,7 +23,7 @@ http.createServer((req, res) => {
id: path.split('/')[0]
}

if (ctype.indexof('/json') > -1) {
if (ctype.indexOf('application/json') > -1) {
let data = ''
req.on('data', (chunk) => { data += chunk })
req.on('end', () => {
Expand All @@ -33,5 +34,5 @@ http.createServer((req, res) => {
return post(req, res, null)
}
}).listen(process.env.PORT || 5000, () => {
console.log('Listening for requests');
debug('Listening for requests');
});
24 changes: 2 additions & 22 deletions lib/formparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import busboy from 'busboy'
const debug = require('debug')('lambda-form')

export default (req, temp) => {
// convert event to stream
const ctype = req.headers['content-type'] || req.headers['Content-Type']
const ctype = req.headers['Content-Type'] || req.headers['content-type']
const rst = { fields: {}, files: {} }

return new Promise( (resolve) => {
try {
if (ctype.indexOf('/json') > -1) {
if (ctype.indexOf('application/json') > -1) {
rst.fields = JSON.parse(req.rawBody || req.body)
return resolve(rst)
} else {
Expand Down Expand Up @@ -41,29 +40,10 @@ export default (req, temp) => {
}

return bb.end()

/*
const parser = new Multipart(req)
return parser.on('finish', (result) => {
const rst = {fields: result.fields, files: {}}
if (result.files) {
result.files.forEach((f) => {
const pass = new stream.PassThrough()
f.pipe(pass)
rst.files[f.name] = { name: f.filename, pass: pass, f: f, type: f.headers['content-type'] }
})
}
resolve(rst)
})
*/
}
} catch(e) {
debug('error parsing form body ', e)
return resolve({err: 'Form data is invalid: parsing error'})
}

return resolve({err: `Invalid form post type ${ctype}`})
})
}
1 change: 0 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const debug = require('debug')('lambda-form')
const rspHeaders = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lambda-form",
"version": "1.2.2",
"version": "1.2.3",
"description": "A form submission handler using Serverless and AWS Lambda",
"main": "handler.js",
"scripts": {
Expand Down

0 comments on commit 596e1a6

Please sign in to comment.