Last active
May 31, 2017 23:05
-
-
Save stef-levesque/2e2c0fe6d33485dc11af3a4de8845648 to your computer and use it in GitHub Desktop.
WebDAV server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webdav", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"author": "", | |
"license": "", | |
"dependencies": { | |
"jsDAV": "^0.3.4" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var os = require("os"); | |
var jsDAV = require("jsDAV/lib/jsdav"); | |
var folder = __dirname + "/data"; | |
var port = 8000; | |
var host = "127.0.0.1"; | |
if (process.argv.length > 2) { | |
folder = process.argv[2]; | |
} | |
if (process.argv.length > 3) { | |
port = parseInt(process.argv[3], 10); | |
} | |
if (!fs.existsSync(folder)) { | |
console.log("ERROR: path " + folder + " does not exists"); | |
process.exit(1); | |
} | |
if (process.argv.length > 4) { | |
host = process.argv[4]; | |
} else { | |
var ifaces = os.networkInterfaces(); | |
Object.keys(ifaces).forEach(function (dev) { | |
ifaces[dev].forEach(function (details) { | |
if (details.family === 'IPv4' && details.address !== '127.0.0.1') { | |
host = details.address; | |
} | |
}); | |
}); | |
} | |
//jsDAV.debugMode = true; | |
var jsDAV_Locks_Backend_FS = require("jsDAV/lib/DAV/plugins/locks/fs"); | |
var jsDAV_Auth_Backend_File = require("jsDAV/lib/DAV/plugins/auth/file"); | |
jsDAV.createServer({ | |
node: folder, | |
locksBackend: jsDAV_Locks_Backend_FS.new(folder) | |
// authBackend: jsDAV_Auth_Backend_File.new("./myhtdigest"), | |
//realm: "jsdavtest" | |
}, port, host); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment