Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding example to allow cross-domain requests if the client JavaScrip…

…t isn't on the same domain as the Node.js server. Updating README.md with instructions.
  • Loading branch information...
commit aea030221e49dc11e94be5cae480e00be53d1f97 1 parent 98e8cf0
@ibjhb authored
Showing with 40 additions and 0 deletions.
  1. +7 −0 samples/Node.js/README.md
  2. +33 −0 samples/Node.js/app_crossDomain.js
View
7 samples/Node.js/README.md
@@ -9,3 +9,10 @@ To install and run:
node app.js
The browse to [localhost:3000](http://localhost:3000).
+
+
+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 '*'. For an example, use the following:
+
+ node app_crossDomain.js
+
+Then in public/index.html, on line 49, update the target with your server's address. For example: http://www.example.com/upload
View
33 samples/Node.js/app_crossDomain.js
@@ -0,0 +1,33 @@
+var express = require('express');
+var form = require('connect-form');
+var resumable = require('./resumable-node.js')('/tmp/resumable.js/');
+var app = express.createServer(form({keepExtensions:true}));
+
+// Host most stuff in the public folder
+app.use(express.static(__dirname + '/public'));
+
+// Handle uploads through Resumable.js
+app.post('/upload', function(req, res){
+ resumable.post(req, function(status, filename, original_filename, identifier){
+ console.log('POST', status);
+ res.send(status, {
+ 'Access-Control-Allow-Origin': '*'
+ });
+ });
+});
+// Handle status checks on chunks through Resumable.js
+app.options('/upload', function(req, res){
+ console.log('OPTIONS');
+ res.send(true, {
+ 'Access-Control-Allow-Origin': '*'
+ }, 200);
+});
+
+app.get('/upload', function(req, res){
+ resumable.get(req, function(status, filename, original_filename, identifier){
+ console.log('GET', status);
+ res.send(status, (status == 'found' ? 200 : 404));
+ });
+});
+
+app.listen(3000);
Please sign in to comment.
Something went wrong with that request. Please try again.