michael pirms 4 gadiem
vecāks
revīzija
2ed38cb2eb
2 mainītis faili ar 20 papildinājumiem un 3 dzēšanām
  1. +1
    -1
      package.json
  2. +19
    -2
      src/index.ts

+ 1
- 1
package.json Parādīt failu

@@ -6,7 +6,7 @@
"scripts": {
"build": "tsc -p ./tsconfig.json",
"start": "node dist/index.js",
"start-debug": "nodemon --inspect dist/index.js",
"start-debug": "npm run build && node dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {


+ 19
- 2
src/index.ts Parādīt failu

@@ -159,6 +159,7 @@ let httpd: http.Server;

server = new webdav.WebDAVServer(serverOptions);
server.beforeRequest((ctx: webdav.HTTPRequestContext, next) => {
console.log('beforeRequest', ctx.request.method);
if (ctx.request.method === 'OPTIONS') {
ctx.response.setHeader('DAV', '1,2');
ctx.response.setHeader('Access-Control-Allow-Origin', '*');
@@ -171,6 +172,12 @@ let httpd: http.Server;
'Access-Control-Allow-Methods',
'PROPPATCH,PROPFIND,OPTIONS,DELETE,UNLOCK,COPY,LOCK,MOVE,HEAD,POST,PUT,GET',
);
ctx.response.setHeader(
'Allow',
'PROPPATCH,PROPFIND,OPTIONS,DELETE,UNLOCK,COPY,LOCK,MOVE,HEAD,POST,PUT,GET',
);
ctx.response.setHeader(
'Access-Control-Expose-Headers',
'DAV, Content-Length, Allow',
@@ -178,11 +185,13 @@ let httpd: http.Server;
ctx.response.setHeader('MS-Author-Via', 'DAV');
ctx.setCode(200);
ctx.exit();
} else {
}
else {
next();
}
});
server.afterRequest((_arg, next) => {
server.afterRequest((_ctx: webdav.HTTPRequestContext, next) => {
console.log('After request');
// Display the method, the URI, the returned status code and the returned message
/*
console.log(
@@ -193,6 +202,7 @@ let httpd: http.Server;
// If available, display the body of the response
console.log('RESPONSEBODY', _arg.responseBody);
*/
console.log('Headers',_ctx.response.getHeaders(), 'Headers sent', _ctx.response.headersSent);
next();
});
@@ -203,6 +213,13 @@ let httpd: http.Server;
let bOk = await server.setFileSystemAsync('/' + fsEntry, new webdav.PhysicalFileSystem(realPath));
console.log(`Mounted (${bOk}) /${fsEntry} -> ${realPath}`);
}
let onexit = async () => {
console.log("Terminated");
await server.stopAsync();
process.exit(0);
}
process.on('SIGTERM', onexit);
process.on('SIGINT', onexit);
httpd = await server.startAsync(config.port);
console.log("WebDAV server is listening on port " + config.port);
}


Notiek ielāde…
Atcelt
Saglabāt