UNPKG

2.9 kBJavaScriptView Raw
1/*
2 * @package jsDAV
3 * @subpackage DAV
4 * @copyright Copyright(c) 2011 Ajax.org B.V. <info AT ajax.org>
5 * @author Mike de Boer <info AT mikedeboer DOT nl>
6 * @author Wouter Vroege <wouter AT woutervroege DOT nl>
7 * @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
8 */
9"use strict";
10
11/*
12
13Addressbook/CardDAV server example
14
15This server features CardDAV support
16
17*/
18
19// Database driver to use. 'redis' is the default, but feel free to use anything
20// else supported by jsDAV
21var DB_DRIVER = "redis";
22
23var jsDAV = require("./../lib/jsdav");
24jsDAV.debugMode = true;
25var jsDAV_Auth_Backend = require("./../lib/DAV/plugins/auth/" + DB_DRIVER);
26var jsDAVACL_PrincipalBackend = require("./../lib/DAVACL/backends/" + DB_DRIVER);
27var jsCardDAV_Backend = require("./../lib/CardDAV/backends/" + DB_DRIVER);
28// node classes:
29var jsDAVACL_PrincipalCollection = require("./../lib/DAVACL/principalCollection");
30var jsCardDAV_AddressBookRoot = require("./../lib/CardDAV/addressBookRoot");
31// plugins:
32var jsDAV_Auth_Plugin = require("./../lib/DAV/plugins/auth");
33var jsDAV_Browser_Plugin = require("./../lib/DAV/plugins/browser");
34var jsCardDAV_Plugin = require("./../lib/CardDAV/plugin");
35var jsDAVACL_Plugin = require("./../lib/DAVACL/plugin");
36
37var Db = require("./../lib/shared/backends/" + DB_DRIVER);
38var DB_INIT = require("./data/addressbook/" + DB_DRIVER);
39
40// Make sure this setting is turned on and reflect the root url for your WebDAV server.
41// This can be for example the root / or a complete path to your server script
42var baseUri = "/";
43
44// Arguments to be passed to the function that establishes a connection with the db
45var DB_ARGS = {};
46/* DB arguments for the mongo driver:
47var DB_ARGS = {
48 host: "localhost", //optional, default = "localhost"
49 db: "jsdav", //optional, default = "jsdav"
50 port: 27017, //optional, default = 27017
51 //username: "", //optional, if both username and password are provided, authentication will be performed before returning connection
52 //password: "" //see above
53};*/
54
55// Database connection
56Db.getConnection(DB_ARGS, function(err, db) {
57 if (err)
58 throw err;
59
60 DB_INIT.init(db, false, function(err) {
61 if (err)
62 throw err;
63
64 var authBackend = jsDAV_Auth_Backend.new(db);
65 var principalBackend = jsDAVACL_PrincipalBackend.new(db);
66 var carddavBackend = jsCardDAV_Backend.new(db);
67
68 // Setting up the directory tree
69 var nodes = [
70 jsDAVACL_PrincipalCollection.new(principalBackend),
71 jsCardDAV_AddressBookRoot.new(principalBackend, carddavBackend)
72 ];
73
74 jsDAV.createServer({
75 node: nodes,
76 baseUri: baseUri,
77 authBackend: authBackend,
78 realm: "jsDAV",
79 plugins: [jsDAV_Auth_Plugin, jsDAV_Browser_Plugin, jsCardDAV_Plugin, jsDAVACL_Plugin]
80 }, 8000);
81
82 });
83});