Skip to content

Commit

Permalink
Update node.js sample app to be compatible with newer node.js versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Palmhøj committed May 3, 2016
1 parent f3085f6 commit 9c59976
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
13 changes: 9 additions & 4 deletions samples/Node.js/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Sample code for Node.js

This sample is written for [Node.js 0.10+](http://nodejs.org/) and requires [Express 4+](http://expressjs.com/) to make the sample code cleaner.
This sample is written for [Node.js 0.10+](http://nodejs.org/) and requires
[Express 4+](http://expressjs.com/) to make the sample code cleaner.

To install and run:

Expand All @@ -10,9 +11,13 @@ To install and run:

Then browse to [localhost:3000](http://localhost:3000).


## Enabling Cross-domain Uploads

If you would like to load the resumable.js library from one domain and have your Node.js reside on another, you must allow 'Access-Control-Allow-Origin' from '*'. Please remember, there are some potential security risks with enabling this functionality. If you would still like to implement cross-domain uploads, open app.js and uncomment lines 24-31 and uncomment line 17.
If you would like to load the resumable.js library from one domain and have your
Node.js reside on another, you must set the header
`Access-Control-Allow-Origin: *`. Please remember, there are some potential
security risks with enabling this functionality. If you would still like to
implement cross-domain uploads, open app.js and uncomment lines 12-15.

Then in public/index.html, on line 49, update the target with your server's address. For example: target:'http://www.example.com/upload'
Then in public/index.html, on line 49, update the target with your servers
address. For example: target:'http://www.example.com/upload'
29 changes: 9 additions & 20 deletions samples/Node.js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,28 @@ app.use(express.static(__dirname + '/public'));

app.use(multipart());

// Uncomment to allow CORS
// app.use(function (req, res, next) {
// res.header('Access-Control-Allow-Origin', '*');
// next();
// });

// Handle uploads through Resumable.js
app.post('/upload', function(req, res){

// console.log(req);

resumable.post(req, function(status, filename, original_filename, identifier){
console.log('POST', status, original_filename, identifier);

res.send(status, {
// NOTE: Uncomment this funciton to enable cross-domain request.
//'Access-Control-Allow-Origin': '*'
});
res.send(status);
});
});

// Handle cross-domain requests
// NOTE: Uncomment this funciton to enable cross-domain request.
/*
app.options('/upload', function(req, res){
console.log('OPTIONS');
res.send(true, {
'Access-Control-Allow-Origin': '*'
}, 200);
});
*/

// Handle status checks on chunks through Resumable.js
app.get('/upload', function(req, res){
resumable.get(req, function(status, filename, original_filename, identifier){
console.log('GET', status);
res.send((status == 'found' ? 200 : 404), status);
});
});
});
});

app.get('/download/:identifier', function(req, res){
resumable.write(req.params.identifier, res);
Expand Down

0 comments on commit 9c59976

Please sign in to comment.