Skip to content

Commit 0bc3801

Browse files
committed
Simplified the README.md
1 parent 4781457 commit 0bc3801

File tree

1 file changed

+23
-335
lines changed

1 file changed

+23
-335
lines changed

README.md

Lines changed: 23 additions & 335 deletions
Original file line numberDiff line numberDiff line change
@@ -7,365 +7,53 @@
77
[![License](https://img.shields.io/npm/l/webdav-server.svg)](http://unlicense.org/)
88
[![npm Version](https://img.shields.io/npm/v/webdav-server.svg)](https://www.npmjs.com/package/webdav-server)
99

10-
# Index
10+
# Description
1111

12-
* Disclaimer / Project information
13-
* Install
14-
* Usage
15-
* Import
16-
* Create server
17-
* Options
18-
* Sample
19-
* Resources
20-
* Root resource
21-
* Resource creation
22-
* Authentication / Privileges / User management
23-
* User management
24-
* Authentication
25-
* Privileges
26-
* Control the response body type
27-
* Persistence
28-
* Overview
29-
* Example
30-
* Save
31-
* Load
12+
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!
3213

33-
# Disclaimer / Project information
14+
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`](https://www.npmjs.com/package/cwdav)), etc...
15+
16+
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](https://github.com/OpenMarshal/npm-WebDAV-Server/wiki).
17+
18+
# Project information
19+
20+
You can find the documentation [here](https://github.com/OpenMarshal/npm-WebDAV-Server/wiki).
3421

3522
Find more details on the development process at [https://github.com/OpenMarshal/npm-WebDAV-Server/projects/1](https://github.com/OpenMarshal/npm-WebDAV-Server/projects/1).
3623

3724
This project rely upon the [RFC4918](http://www.webdav.org/specs/rfc4918.html).
3825

39-
The full set of the standard WebDAV methods are implemented :
40-
* HEAD (resource ping)
41-
* GET (file get content)
42-
* MKCOL (directory creation)
43-
* PROPFIND (get file information)
44-
* PROPPATCH (set/remove resource properties)
45-
* PUT/POST (set the content of a file and create it if it doesn't exist)
46-
* OPTIONS (list available methods)
47-
* DELETE (delete a resource)
48-
* MOVE (move a resource)
49-
* COPY (copy a resource)
50-
* LOCK/UNLOCK (reserve a resource for use)
51-
5226
This is an active project. Do not hesitate to post an issue if you have an idea or if you encounter a problem.
5327

54-
Currently working on providing a real documentation of the module.
55-
The documentation on this page will lightened. The more complete version will be available [here](https://github.com/OpenMarshal/npm-WebDAV-Server/wiki).
56-
5728
# Install
5829

5930
```bash
6031
npm install webdav-server
6132
```
6233

63-
# Usage
34+
# Quick usage
6435

65-
## Import
66-
67-
### NodeJS
68-
```javascript
69-
const webdav = require('webdav-server')
70-
```
71-
72-
### TypeScript
7336
```typescript
74-
import * as webdav from 'webdav-server'
75-
```
76-
77-
## Create server
78-
79-
### NodeJS / TypeScript
80-
```javascript
81-
const server = new webdav.WebDAVServer(options);
82-
```
83-
84-
*options* is of type `WebDAVServerOptions`. This interface can be found in `webdav.WebDAVServerOptions`
85-
86-
### Options
87-
Key | Default value | Description
88-
-|-|-
89-
requireAuthentification | `false` | Define if your require to be authenticated.
90-
httpAuthentication | `new HTTPBasicAuthentication('default realm')` | Define the object which will provide the authentication method (HTTP : Basic, Digest, custom, etc).
91-
privilegeManager | `new FakePrivilegeManager()` | Allow to check the privileges of the user (grant or restrict access).
92-
rootResource | `new RootResource()` | The root resource to use as `/`.
93-
userManager | `new SimpleUserManager()` | Define the object which will provide the users.
94-
lockTimeout | `3600` | Define the lock timeout.
95-
canChunk | `true` | Define if the server must recreate the full message or if it must keep it splitted (if `false`, `IResource.append(...)` will never be called, only `IResource.write(...)`). Set the value to `false` if you encounter a problem with the order of the content, this feature hasn't been tested enough.
96-
hostname | `'::'` | Define the scope of the listening server.
97-
port | `1900` | The default port to use if no port is specified when calling `server.start()`.
98-
strictMode | `false` | Define if the server must blindly follow the WebDAV RFC (`true`) or allow more flexibility (`false`) (for instance disallow a body in a request which doesn't use a body).
99-
autoSave | `null` | Define an auto-saver to automatically save the state of the server and taking care of any conflict which can happen while writing the persistence file and limit the number of writes when some are not required (3 PUT in a row will lead to 2 writes, the first and last ones) (the GET request, for instance, doesn't lead to a write). The `autoSave` option is an `object` of type : `{ treeFilePath : string, tempTreeFilePath : string, onSaveError ?: (error : Error) => void, streamProvider ?: (inputStream : Writable, callback : (outputStream ?: Writable) => void) => void }`.
100-
101-
## Sample
102-
103-
### NodeJS / TypeScript
104-
```javascript
105-
// Typescript
37+
// TypeScript
10638
import * as webdav from 'webdav-server'
10739
// Javascript
10840
const webdav = require('webdav-server');
10941

110-
// Create a WebDAV server with options
42+
const um = new webdav.SimpleUserManager();
43+
const user = um.addUser('myUsername', 'myPassword', false);
44+
45+
const pm = new webdav.SimplePathPrivilegeManager();
46+
pm.setRights(user, '/', [ 'all' ]);
47+
11148
const server = new webdav.WebDAVServer({
49+
privilegeManager: pm,
50+
userManager: um,
51+
isVerbose: true,
11252
port: 1900
11353
});
114-
115-
// Create a virtual file
116-
var file = new webdav.VirtualFile('testFile.txt');
117-
// Set the content of the virtual file
118-
file.write(true, (e, writer) => {
119-
if(e) throw e;
120-
121-
writer.end('The content of the virtual file.', (e) => {
122-
if(e) throw e;
123-
124-
// Add the virtual resources to the root folder
125-
// Note that you can add resources even when the
126-
// server is running
127-
server.addResourceTree({
128-
r: new webdav.VirtualFolder('testFolder'),
129-
c: [{
130-
r: new webdav.VirtualFolder('test1'),
131-
c: new webdav.VirtualFile('test2')
132-
}, {
133-
r: new webdav.VirtualFolder('test2'),
134-
c: [{
135-
r: new webdav.VirtualFolder('test1'),
136-
c: new webdav.VirtualFile('test2')
137-
},{
138-
r: new webdav.VirtualFolder('test2'),
139-
c: new webdav.VirtualFile('test2')
140-
}]
141-
}]
142-
}, (e) => {
143-
if(e) throw e;
144-
145-
// Start the server
146-
server.start(httpServer => {
147-
console.log('Server started with success on the port : ' + httpServer.address().port);
148-
149-
// [...]
150-
151-
// Stop the server
152-
server.stop(() => {
153-
console.log('Server stopped with success!');
154-
})
155-
});
156-
});
157-
});
158-
})
54+
server.start(() => console.log('READY'));
15955
```
16056

161-
In this example, the resource tree will be the following :
162-
Path|Class
163-
-|-
164-
`/` | RootResource
165-
`/testFile.txt` | VirtualFile
166-
`/testFolder` | VirtualFolder
167-
`/testFolder/testFile2.txt` | PhysicalFile
168-
`/testFolder/testFolder2` | PhysicalFolder
169-
170-
# Resources
171-
172-
There are two kinds of resource provided : the virtual file/folder and the physical file/folder. The virtual resource is a resource you create and keep in memory. The physical resource is a resource present in your current file system.
173-
174-
You can create a custom resource by creating an object or a class which will inherit the members of the IResource class.
175-
176-
The type of a resource can be (class ResourceType) :
177-
178-
-|Is a directory|Is not a directory
179-
-|-|-
180-
**Is a file**|Hibrid|File
181-
**Is not a file**|Directory|NoResource
182-
183-
Here are the differences between the resource types :
184-
-|Hibrid|File|Directory|NoResource
185-
-|-|-|-|-
186-
**Can have content**|yes|yes|no|no
187-
**Can have child resource**|yes|no|yes|no
188-
**Is standard (RFC)**|no|yes|yes|no
189-
190-
## Root resource
57+
More examples at the [example page of the wiki](https://github.com/OpenMarshal/npm-WebDAV-Server/wiki/Examples).
19158

192-
The root resource (`class RootResource`) is a resource which disallow almost everything (no copy, no move, etc), but provides a static root folder. It is instanciated by default if no `option.rootResource` is provided to the constructor of the server. This resource is a virtual resource. That's why, if you create a child through the WebDAV interface (HTTP), it will be a virtual resource.
193-
194-
Method|Must be allowed?||Method|Must be allowed?
195-
-|-|-|-|-
196-
**create** | no || **delete** | no
197-
**moveTo** | no || **rename** | no
198-
**append** | may || **write** | may
199-
**read** | may || **mimeType** | may
200-
**size** | may || **getLocks** | yes
201-
**setLock** | yes || **removeLock** | yes
202-
**canLock** | yes || **getAvailableLocks** | yes
203-
**canRemoveLock** | yes || **getLock** | yes
204-
**addChild** | yes || **removeChild** | yes
205-
**getChildren** | yes || **setProperty** | yes
206-
**getProperty** | yes || **removeProperty** | yes
207-
**getProperties** | yes || **creationDate** | yes
208-
**lastModifiedDate** | may || **webName** | yes
209-
**type** | yes
210-
211-
## Resource creation
212-
213-
When a user create a resource through the WebDAV interface (HTTP), it will inherit the parent file system manager. For instance, if you create a file or a folder as a child of the path `/myFolder` and `myFolder` contains a virtual file system manager, then the file or folder created will be a virtual file or a virtual folder. The same reflection can be made with the physical resources and custom resources. The file system manager is in charge of the creation of the resource object (not to call `.create(...)`, just the object). This way, you can have a behavior for a resource (the resource class itself) and a different behavior for its children (the file system manager).
214-
215-
If you create a resource through the module (for instance in JavaScript), you can add as child of a resource the kind of resource you want. You are limited only by the type of the parent resource and its implementation.
216-
217-
# Authentication / Privileges / User management
218-
219-
## User management
220-
221-
The user management is get through an instance of the class `IUserManager` which provide users of the class `IUser`.
222-
223-
A `IUserManager` class must contains the following public fields :
224-
```typescript
225-
interface IUserManager
226-
{
227-
getUserByName(name : string, callback : (error : Error, user : IUser) => void)
228-
getDefaultUser(callback : (user : IUser) => void)
229-
getUsers(callback : (error : Error, users : IUser[]) => void)
230-
}
231-
```
232-
233-
A `IUser` class must contains the following public fields :
234-
```typescript
235-
interface IUser
236-
{
237-
isAdministrator : boolean
238-
isDefaultUser : boolean
239-
password : string
240-
username : string
241-
}
242-
```
243-
244-
The `IUserManager` class can get a user by name ; it can get the list of all users ; and it can get the default user.
245-
246-
The default user is the user which is given to an unauthentication user. This way, an unauthenticated user will have the privileges of the default user. If the server's option `requireAuthentification` equals `true`, the default user will not be used.
247-
248-
Thanks to the server's option `userManager`, the user manager can be set with a custom instance. This way, you can create a user manager which, for instance, retrieve its users from a database.
249-
250-
## Authentication
251-
252-
The authentication is made through the HTTP authentication system. The standard authentication systems use a HTTP header to get the user credentials.
253-
254-
Thanks to the server's option `httpAuthentication`, it is possible to define the authentication system you want to use, even a custom one.
255-
256-
It musts inherit from the interface `HTTPAuthentication` :
257-
```typescript
258-
interface HTTPAuthentication
259-
{
260-
realm : string
261-
262-
askForAuthentication() : any
263-
getUser(arg : MethodCallArgs, userManager : IUserManager, callback : (error : Error, user : IUser) => void)
264-
}
265-
```
266-
267-
The `askForAuthentication()` method is used by the server to know what headers the method needs to add to its response.
268-
269-
The `getUser()` method is used by the server to get the user of the current request.
270-
271-
There are two authentication system implemented in the modules : `HTTPBasicAuthentication` and `HTTPDigestAuthentication`.
272-
273-
The class `HTTPBasicAuthentication` implements the `Basic` authentication system and is the most commonly used on internet. The class `HTTPDigestAuthentication` implements the `Digest` authentication system and provides a more secure way to authenticate.
274-
275-
## Privileges
276-
277-
The privileges of a user upon a resource is defined by the instance of the interface `IPrivilegeManager` provided in the server's option `privilegeManager`. This object provides a list of methods to tell the server that a resource is accessible by a user or if it is not.
278-
279-
Here is the interface `IPrivilegeManager` :
280-
```typescript
281-
interface IPrivilegeManager
282-
{
283-
canCreate : PrivilegeManagerMethod
284-
canDelete : PrivilegeManagerMethod
285-
canMove : PrivilegeManagerMethod
286-
canRename : PrivilegeManagerMethod
287-
canAppend : PrivilegeManagerMethod
288-
canWrite : PrivilegeManagerMethod
289-
canRead : PrivilegeManagerMethod
290-
canSource : PrivilegeManagerMethod // Allow to access to the source
291-
// of a resource when it is
292-
// requested by the 'source' header
293-
canGetMimeType : PrivilegeManagerMethod
294-
canGetSize : PrivilegeManagerMethod
295-
canListLocks : PrivilegeManagerMethod
296-
canSetLock : PrivilegeManagerMethod
297-
canRemoveLock : PrivilegeManagerMethod
298-
canGetAvailableLocks : PrivilegeManagerMethod
299-
canGetLock : PrivilegeManagerMethod
300-
canAddChild : PrivilegeManagerMethod
301-
canRemoveChild : PrivilegeManagerMethod
302-
canGetChildren : PrivilegeManagerMethod
303-
canSetProperty : PrivilegeManagerMethod
304-
canGetProperty : PrivilegeManagerMethod
305-
canGetProperties : PrivilegeManagerMethod
306-
canRemoveProperty : PrivilegeManagerMethod
307-
canGetCreationDate : PrivilegeManagerMethod
308-
canGetLastModifiedDate : PrivilegeManagerMethod
309-
canGetWebName : PrivilegeManagerMethod
310-
canGetType : PrivilegeManagerMethod
311-
}
312-
```
313-
With :
314-
```typescript
315-
type PrivilegeManagerCallback = (error : Error, hasAccess : boolean) => void;
316-
type PrivilegeManagerMethod = (arg : MethodCallArgs, resource : IResource, callback : PrivilegeManagerCallback) => void
317-
```
318-
319-
The request relative information (the user, the request, etc) are in the `arg` parameter.
320-
321-
# Control the response body type
322-
323-
By default, when there is a body in the WebDAV response, it will be in XML. If there is a `Accept` header in the request with the `json` type as a priority, the result will be in JSON.
324-
325-
# Persistence
326-
327-
## Overview
328-
329-
It is possible to save your architecture using `server.save(...)` and you can reload it with `server.load(...)`.
330-
The serialization/unserialization is made by the file system manager of the resource.
331-
The children of a resource are managed by the server itself, not by the file system manager.
332-
You can save and load while the server is running, but if a request is processing, it may lead to an inconsistent state.
333-
A trick would be to save when a request is completed (`server.afterRequest(...)`).
334-
335-
## Example
336-
337-
### Save
338-
339-
```javascript
340-
server.save((e, data) => {
341-
if(e)
342-
throw e;
343-
344-
fs.writeFile('persistence.data', JSON.stringify(data), (e) => {
345-
if(e)
346-
throw e;
347-
348-
// [...]
349-
})
350-
})
351-
```
352-
353-
### Load
354-
355-
```javascript
356-
fs.readFile('persistence.data', (e, data) => {
357-
if(e)
358-
throw e;
359-
360-
server.load(JSON.parse(data), [
361-
new webdav.PhysicalFSManager(),
362-
new webdav.VirtualFSManager(),
363-
new webdav.RootFSManager()
364-
], (e) => {
365-
if(e)
366-
throw e;
367-
368-
// [...]
369-
});
370-
})
371-
```
59+
More information/possibilities in the [documentation](https://github.com/OpenMarshal/npm-WebDAV-Server/wiki).

0 commit comments

Comments
 (0)