1 | #happn-3 configuration options:
|
2 | *What follows is the full configuration options for a happn server and client, showing what the defaults are when the config is omitted:*
|
3 |
|
4 | ##server
|
5 | ```javascript
|
6 | var serverConfig = {
|
7 |
|
8 | port: 55000, //happn-3 port
|
9 | secure: true, //false by default
|
10 | encryptPayloads: true,//false by default
|
11 |
|
12 | services: {
|
13 |
|
14 | security: {
|
15 |
|
16 | config: {
|
17 |
|
18 | sessionTokenSecret: "TESTTOKENSECRET",//how our session tokens are encrypted
|
19 |
|
20 | keyPair: {//ECDSA keypair
|
21 | privateKey: 'Kd9FQzddR7G6S9nJ/BK8vLF83AzOphW2lqDOQ/LjU4M=',
|
22 | publicKey: 'AlHCtJlFthb359xOxR5kiBLJpfoC2ZLPLWYHN3+hdzf2'
|
23 | },
|
24 |
|
25 | adminUser: {
|
26 | password: 'happn', //happn by default, console logs a warning if secure:true and no admin password specified - breaks if ENV is production
|
27 | publicKey: 'AlHCtJlFthb359xOxR5kiBLJpfoC2ZLPLWYHN3+hdzf2'
|
28 | },
|
29 |
|
30 | profiles: [ //profiles are in an array, in descending order of priority, so if you fit more than one profile, the top profile is chosen
|
31 | {
|
32 | name: "web-session",
|
33 | session: {//how we match this profile to a session, mongo-like filter
|
34 | $and: [{
|
35 | user: {username: {$eq: 'WEB_SESSION'}},
|
36 | type: {$eq: 0}
|
37 | }]
|
38 | },
|
39 | policy: {
|
40 | ttl: '4 seconds',
|
41 | inactivity_threshold: '2 seconds'//this is costly, as we need to store state on the server side
|
42 | }
|
43 | }
|
44 | }
|
45 | },
|
46 |
|
47 | data: {
|
48 | config: {
|
49 | fsync: true, //if this is true - any nedb datastore with a file configured will immediately write-sync to it's file
|
50 | autoUpdateDBVersion:false, //if your db version is 0 and the db version in package.json is 1 the db will automatically be updated
|
51 | datastores: [//you can choose where you want the data persisted depending on the key
|
52 | {
|
53 | name: 'memory',
|
54 | isDefault: true,// if a datastore with a matching pattern cannot be found - this one will be used
|
55 | patterns: [
|
56 | '/any/*'
|
57 | ]
|
58 | },
|
59 | {
|
60 | name: 'persisted',
|
61 | settings: {
|
62 | compactInterval: 5000,//compact every 5 seconds
|
63 | filename: [testfilePath],//where you want your data persisted to
|
64 | },
|
65 | patterns: [
|
66 | '/save_to_file/*'
|
67 | ]
|
68 | }
|
69 | ]
|
70 | }
|
71 | },
|
72 |
|
73 | transport: {
|
74 | config: {
|
75 | mode: 'https'//'http' by default,
|
76 | certPath: __dirname + '/cert.pem', // optional, defaults creates in home dir
|
77 | keyPath: __dirname + '/key.pem'
|
78 | }
|
79 | },
|
80 |
|
81 | connect: {
|
82 | config: {
|
83 | middleware: {
|
84 | security: {
|
85 | cookieName: 'happn_token', // default shown
|
86 | cookieDomain: '.example.com', // optional, allows for cookie domain control in browser
|
87 | exclusions: [//http paths to exclude from security checks
|
88 | '/test/excluded/specific',
|
89 | '/test/excluded/wildcard/*',
|
90 | ],
|
91 | unauthorizedResponsePath: path.join(__dirname, 'files/unauthorized.html'), // 401 unauthorized response page (not logged in - token invalid)
|
92 | forbiddenResponsePath: path.join(__dirname, 'files/forbidden.html') // 403 forbidden response page (don't have permissions - token valid)
|
93 | }
|
94 | }
|
95 | }
|
96 | },
|
97 |
|
98 | protocol: {
|
99 | config: {
|
100 | inboundLayers: '[inbound plugin]',
|
101 | outboundLayers: '[outbound plugin]',
|
102 | protocols: {'happn': require('happn-protocol')}//array of protocols, ie: MQTT
|
103 | }
|
104 | }
|
105 | }
|
106 | }
|
107 |
|
108 | ```
|
109 |
|
110 | ##websockets client
|
111 | ```javascript
|
112 |
|
113 | var clientConfig = {
|
114 | port:55000,
|
115 | username:'_ADMIN',
|
116 | password:'happn',
|
117 | keyPair: { //ECDSA client keypair
|
118 | privateKey: 'Kd9FQzddR7G6S9nJ/BK8vLF83AzOphW2lqDOQ/LjU4M=',
|
119 | publicKey: 'AlHCtJlFthb359xOxR5kiBLJpfoC2ZLPLWYHN3+hdzf2'
|
120 | },
|
121 | info: {"KEY": "VALUE"}//anything you want to attach to your session
|
122 | loginType:'digest'// you want to use your keypair to login
|
123 | }
|
124 | ```
|