-
Notifications
You must be signed in to change notification settings - Fork 3
/
testserver-multi.ts
99 lines (92 loc) · 2.85 KB
/
testserver-multi.ts
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* This file requires the --experimental-specifier-resolution=node option.
*
* env NODE_OPTIONS='--experimental-specifier-resolution=node' npx tsx testserver-multi.ts testroot
*/
import { hostname } from 'node:os';
import { dirname, resolve, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import fs, { constants } from 'node:fs';
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 PamAuthenticator from './packages/authenticator-pam/dist/index.js';
import InsecureAuthenticator from './packages/authenticator-none/dist/index.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const debug = createDebug('nephele:testserver-multi');
const app = express();
const host = hostname();
const port = 8080;
const root = process.argv.length > 2 ? resolve(process.argv[2]) : __dirname;
const pam = !process.env.NOPAM;
const instanceDate = new Date();
try {
fs.accessSync(join(root, 'First'), constants.F_OK);
} catch (e) {
fs.mkdirSync(join(root, 'First'));
}
try {
fs.accessSync(join(root, 'Second'), constants.F_OK);
} catch (e) {
fs.mkdirSync(join(root, 'Second'));
}
app.use(
'/',
server({
adapter: async (_request, _response) => {
return {
'/': new VirtualAdapter({
files: {
properties: {
creationdate: instanceDate,
getlastmodified: instanceDate,
owner: 'root',
},
locks: {},
children: [
{
name: 'Directory (1)',
properties: {
creationdate: instanceDate,
getlastmodified: instanceDate,
owner: 'root',
},
locks: {},
children: [],
},
{
name: 'Directory (2)',
properties: {
creationdate: instanceDate,
getlastmodified: instanceDate,
owner: 'root',
},
locks: {},
children: [],
},
],
},
}),
'/Directory (1)/': new FileSystemAdapter({
root: join(root, 'First'),
}),
'/Directory (2)/': new FileSystemAdapter({
root: join(root, 'Second'),
}),
};
},
authenticator: pam ? new PamAuthenticator() : new InsecureAuthenticator(),
}),
);
app.listen(port, () => {
debug(`Listening on ${host}:${port}.`);
debug(
`Serving files from user "${join(root, 'First')}" and "${join(
root,
'Second',
)}" directories.`,
);
console.log(`Example Nephele WebDAV server listening on port ${port}`);
});