WebDAV Server for npm
Description
This server can use physical resources (files and folders on a hard drive, for instance), virtual resources (in-memory files and folders), processed/computed resources (for instance a file which provide the content of a remote web page), customized resources (whatever you created, whatever you can imagine), and use all of them on the same server instance. And it's easy to integrate in your JavaScript code!
You can use it to provide human readable content, easily manageable thanks to the WebDAV clients, or use a temporary and virtual file system to share information between running programs, or store crypted documents while still being able to use them as if they were not crypted (take a look at cwdav
), etc...
This is a fully configurable server. You can use you own user manager, your own resources, your own HTTP methods, your own way to save the state of the server, etc... Find more in the documentation.
Project information
Here are some project related links :
You can find a list of file systems here :
This project rely upon the RFC4918.
This is an active project. Do not hesitate to post an issue if you have an idea or if you encounter a problem.
The project comes with two versions : the obselete version 1 and the version 2. Prefer using the version 2. At the moment, for compatibility issues, to access the version you must use the v2
namespace.
Install
npm install webdav-server
Quick usage
Very simple usage :
import { v2 as webdav } from 'webdav-server'
const webdav = require('webdav-server').v2;
const server = new webdav.WebDAVServer({
port: 1900
});
server.start(() => console.log('READY'));
With some logs :
import { v2 as webdav } from 'webdav-server'
const webdav = require('webdav-server').v2;
const server = new webdav.WebDAVServer({
port: 1900
});
server.afterRequest((arg, next) => {
console.log('>>', arg.request.method, arg.requested.uri, '>', arg.response.statusCode, arg.response.statusMessage);
console.log(arg.responseBody);
next();
});
server.start(() => console.log('READY'));
With a user manager, privilege manager and serialization (save/load the state of the server) :
import { v2 as webdav } from 'webdav-server'
const webdav = require('webdav-server').v2;
const userManager = new webdav.SimpleUserManager();
const user = userManager.addUser('username', 'password', false);
const privilegeManager = new webdav.SimplePathPrivilegeManager();
privilegeManager.setRights(user, '/', [ 'all' ]);
const server = new webdav.WebDAVServer({
httpAuthentication: new webdav.HTTPDigestAuthentication(userManager, 'Default realm'),
privilegeManager: privilegeManager,
port: 2000,
autoSave: {
treeFilePath: 'data.json'
}
});
server.autoLoad((e) => {
if(e)
{
server.rootFileSystem().addSubTree(server.createExternalContext(), {
'folder1': {
'file1.txt': webdav.ResourceType.File,
'file2.txt': webdav.ResourceType.File
},
'file0.txt': webdav.ResourceType.File
})
}
server.start(() => console.log('READY'));
})
Within Express
:
import { v2 as webdav } from 'webdav-server'
import * as express from 'express'
const webdav = require('webdav-server').v2;
const express = require('express');
const server = new webdav.WebDAVServer();
const app = express();
app.use(webdav.extensions.express('/my/sub/path', server));
app.listen(1901);
More examples at the example page of the wiki.
More information/possibilities in the documentation.