diff --git a/package.json b/package.json index c026443..af1104e 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/index.ts b/src/index.ts index 69a8c2c..64cfe69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); }