-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtestserver-home-noauth.mjs
More file actions
57 lines (51 loc) · 1.49 KB
/
testserver-home-noauth.mjs
File metadata and controls
57 lines (51 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* node testserver-home-noauth.mjs
*/
import { userInfo, hostname } from 'node:os';
import express from 'express';
import createDebug from 'debug';
import server from './packages/nephele/dist/index.js';
import FileSystemAdapter from './packages/adapter-file-system/dist/index.js';
import VirtualAdapter from './packages/adapter-virtual/dist/index.js';
import InsecureAuthenticator from './packages/authenticator-none/dist/index.js';
const debug = createDebug('nephele:testserver-home');
const app = express();
const host = hostname();
const port = 8080;
const instanceDate = new Date();
app.use(
'/',
server({
adapter: async (_request, response) => {
if (response.locals.user == null) {
return new VirtualAdapter({
files: {
properties: {
creationdate: instanceDate,
getlastmodified: instanceDate,
owner: 'root',
},
locks: {},
children: [],
},
});
}
try {
const root = userInfo().homedir;
return new FileSystemAdapter({ root });
} catch (e) {
throw new Error("Couldn't mount user directory as server root.");
}
},
authenticator: new InsecureAuthenticator(),
}),
);
app.listen(port, (err) => {
if (err) {
console.error(err);
return;
}
debug(`Listening on ${host}:${port}.`);
debug(`Serving files from user home directory.`);
console.log(`Example Nephele WebDAV server listening on port ${port}`);
});