diff --git a/package-lock.json b/package-lock.json index 3152bd96..ca1e0418 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-reveal", - "version": "4.0.0", + "version": "4.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -400,7 +400,6 @@ "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz", "integrity": "sha512-jOdnI/3qTpHABjM5cx1Hc0sKsPoYCp+DP/GJRGtDlPd7fiV9oXGGIcjW/ZOxLIvjGz8MA+uMZI9metHlgqbgwQ==", - "dev": true, "requires": { "@types/node": "*" } @@ -456,7 +455,6 @@ "version": "1.17.1", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.1.tgz", "integrity": "sha512-RoX2EZjMiFMjZh9lmYrwgoP9RTpAjSHiJxdp4oidAQVO02T7HER3xj9UKue5534ULWeqVEkujhWcyvUce+d68w==", - "dev": true, "requires": { "@types/connect": "*", "@types/node": "*" @@ -472,7 +470,6 @@ "version": "3.4.32", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.32.tgz", "integrity": "sha512-4r8qa0quOvh7lGD0pre62CAb1oni1OO6ecJLGCezTmhQ8Fz50Arx9RUszryR8KlgK6avuSXvviL6yWyViQABOg==", - "dev": true, "requires": { "@types/node": "*" } @@ -481,7 +478,6 @@ "version": "0.7.3", "resolved": "https://registry.npmjs.org/@types/cookies/-/cookies-0.7.3.tgz", "integrity": "sha512-NEkYn8pNsYZIxf3ZrjdPoeyueiPc0RbQClUpTwmdHkpmQQ8iDAlQYKpabuegHy7BJcqTteSTkhURMEs9ZxyEWg==", - "dev": true, "requires": { "@types/connect": "*", "@types/express": "*", @@ -499,7 +495,6 @@ "version": "4.17.1", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.1.tgz", "integrity": "sha512-VfH/XCP0QbQk5B5puLqTLEeFgR8lfCJHZJKkInZ9mkYd+u8byX0kztXEQxEk4wZXJs8HI+7km2ALXjn4YKcX9w==", - "dev": true, "requires": { "@types/body-parser": "*", "@types/express-serve-static-core": "*", @@ -510,7 +505,6 @@ "version": "4.16.9", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.16.9.tgz", "integrity": "sha512-GqpaVWR0DM8FnRUJYKlWgyARoBUAVfRIeVDZQKOttLFp5SmhhF9YFIYeTPwMd/AXfxlP7xVO2dj1fGu0Q+krKQ==", - "dev": true, "requires": { "@types/node": "*", "@types/range-parser": "*" @@ -530,8 +524,7 @@ "@types/http-assert": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.1.tgz", - "integrity": "sha512-PGAK759pxyfXE78NbKxyfRcWYA/KwW17X290cNev/qAsn9eQIxkH4shoNBafH37wewhDG/0p1cHPbK6+SzZjWQ==", - "dev": true + "integrity": "sha512-PGAK759pxyfXE78NbKxyfRcWYA/KwW17X290cNev/qAsn9eQIxkH4shoNBafH37wewhDG/0p1cHPbK6+SzZjWQ==" }, "@types/istanbul-lib-coverage": { "version": "2.0.1", @@ -576,14 +569,12 @@ "@types/keygrip": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.1.tgz", - "integrity": "sha1-/1QEYtL7TQqIRBzq8n0oewHD2Hg=", - "dev": true + "integrity": "sha1-/1QEYtL7TQqIRBzq8n0oewHD2Hg=" }, "@types/koa": { "version": "2.0.49", "resolved": "https://registry.npmjs.org/@types/koa/-/koa-2.0.49.tgz", "integrity": "sha512-WQWpCH8O4Dslk8IcXfazff40aM1jXX7BQRbADIj/fKozVPu76P/wQE4sRe2SCWMn8yNkOcare2MkDrnZqLMkPQ==", - "dev": true, "requires": { "@types/accepts": "*", "@types/cookies": "*", @@ -597,7 +588,6 @@ "version": "3.2.4", "resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.4.tgz", "integrity": "sha512-ioou0rxkuWL+yBQYsHUQAzRTfVxAg8Y2VfMftU+Y3RA03/MzuFL0x/M2sXXj3PkfnENbHsjeHR1aMdezLYpTeA==", - "dev": true, "requires": { "@types/koa": "*" } @@ -639,6 +629,14 @@ "@types/koa-send": "*" } }, + "@types/koa-static-server": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@types/koa-static-server/-/koa-static-server-1.3.0.tgz", + "integrity": "sha512-iSAB4/LE5TJvvdtIWjBvdHKAymLeVtW4TlOn1yG1CWRo6MbvZUYTIgnG9F3zyStQzk2J9sa8YnPpLWyLfrWXCw==", + "requires": { + "@types/koa": "*" + } + }, "@types/marked": { "version": "0.6.5", "resolved": "https://registry.npmjs.org/@types/marked/-/marked-0.6.5.tgz", @@ -648,8 +646,7 @@ "@types/mime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz", - "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==", - "dev": true + "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==" }, "@types/minimatch": { "version": "3.0.3", @@ -666,8 +663,7 @@ "@types/node": { "version": "10.14.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.14.18.tgz", - "integrity": "sha512-ryO3Q3++yZC/+b8j8BdKd/dn9JlzlHBPdm80656xwYUdmPkpTGTjkAdt6BByiNupGPE8w0FhBgvYy/fX9hRNGQ==", - "dev": true + "integrity": "sha512-ryO3Q3++yZC/+b8j8BdKd/dn9JlzlHBPdm80656xwYUdmPkpTGTjkAdt6BByiNupGPE8w0FhBgvYy/fX9hRNGQ==" }, "@types/opn": { "version": "5.5.0", @@ -681,8 +677,7 @@ "@types/range-parser": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", - "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==", - "dev": true + "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==" }, "@types/request": { "version": "2.48.3", @@ -700,7 +695,6 @@ "version": "1.13.3", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.3.tgz", "integrity": "sha512-oprSwp094zOglVrXdlo/4bAHtKTAxX6VT8FOZlBKrmyLbNvE1zxZyJ6yikMVtHIvwP45+ZQGJn+FdXGKTozq0g==", - "dev": true, "requires": { "@types/express-serve-static-core": "*", "@types/mime": "*" @@ -4623,7 +4617,8 @@ "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true }, "isexe": { "version": "2.0.0", @@ -5435,29 +5430,6 @@ "passthrough-counter": "^1.0.0" } }, - "koa-router": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/koa-router/-/koa-router-7.4.0.tgz", - "integrity": "sha512-IWhaDXeAnfDBEpWS6hkGdZ1ablgr6Q6pGdXCyK38RbzuH4LkUOpPqPw+3f8l8aTDrQmBQ7xJc0bs2yV4dzcO+g==", - "requires": { - "debug": "^3.1.0", - "http-errors": "^1.3.1", - "koa-compose": "^3.0.0", - "methods": "^1.0.1", - "path-to-regexp": "^1.1.1", - "urijs": "^1.19.0" - }, - "dependencies": { - "koa-compose": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-3.2.1.tgz", - "integrity": "sha1-qFzLQLfZhtjlo0Wzoazo6rz1Tec=", - "requires": { - "any-promise": "^1.1.0" - } - } - } - }, "koa-send": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/koa-send/-/koa-send-5.0.0.tgz", @@ -5469,13 +5441,13 @@ "resolve-path": "^1.4.0" } }, - "koa-static": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/koa-static/-/koa-static-5.0.0.tgz", - "integrity": "sha512-UqyYyH5YEXaJrf9S8E23GoJFQZXkBVJ9zYYMPGz919MSX1KuvAcycIuS0ci150HCoPf4XQVhQ84Qf8xRPWxFaQ==", + "koa-static-server": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/koa-static-server/-/koa-static-server-1.4.0.tgz", + "integrity": "sha512-ZkGzD9+2OZubOL458GL8p7vEGfaneGGKSKIUJw9ftXzn36capQw3Wu5A//o7S10tQNgD1oYs96LGPtqtkcuXbQ==", "requires": { - "debug": "^3.1.0", - "koa-send": "^5.0.0" + "koa-send": "^5.0.0", + "upath": "^1.0.2" } }, "lcid": { @@ -5841,11 +5813,6 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, - "methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" - }, "micromatch": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", @@ -6973,14 +6940,6 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, - "path-to-regexp": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", - "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", - "requires": { - "isarray": "0.0.1" - } - }, "path-type": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-3.0.0.tgz", @@ -9003,8 +8962,7 @@ "upath": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/upath/-/upath-1.2.0.tgz", - "integrity": "sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==", - "dev": true + "integrity": "sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==" }, "uri-js": { "version": "4.2.2", @@ -9015,11 +8973,6 @@ "punycode": "^2.1.0" } }, - "urijs": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", - "integrity": "sha512-xVrGVi94ueCJNrBSTjWqjvtgvl3cyOTThp2zaMaFNGp3F542TR6sM3f2o8RqZl+AwteClSVmoCyt0ka4RjQOQg==" - }, "urix": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz", diff --git a/package.json b/package.json index 209cbf04..5e771b8f 100644 --- a/package.json +++ b/package.json @@ -370,13 +370,13 @@ }, "dependencies": { "@evilz/markdown-it-attrs": "^3.0.1", + "@types/koa-static-server": "^1.3.0", "fs-jetpack": "^2.2.2", "gray-matter": "^4.0.2", "koa": "^2.8.1", "koa-ejs": "^4.2.0", "koa-logger": "^3.2.1", - "koa-router": "^7.4.0", - "koa-static": "^5.0.0", + "koa-static-server": "^1.4.0", "markdown-it": "^10.0.0", "markdown-it-block-embed": "0.0.3", "markdown-it-container": "^2.0.0", diff --git a/src/RevealServer.ts b/src/RevealServer.ts index a745bc0f..4238e608 100644 --- a/src/RevealServer.ts +++ b/src/RevealServer.ts @@ -2,8 +2,7 @@ import * as http from 'http' import * as Koa from 'koa' import * as render from 'koa-ejs' import * as koalogger from 'koa-logger' -import * as Router from 'koa-router' -import * as koastatic from 'koa-static' +import * as serve from 'koa-static-server' import * as path from 'path' import markdown from './Markdown-it' @@ -66,14 +65,11 @@ export class RevealServer { // LOG REQUEST app.use(koalogger((str, args) => {this.logger.log(str)})) - app.use(this.exportMiddleware(exportHTML, () => this.isInExport())) - // For static media or else - const rootDir = this.getRootDir() - if (rootDir) { - app.use(koastatic(rootDir)); - } + // EXPORT + app.use(this.exportMiddleware(exportHTML, () => this.isInExport())) + // EJS VIEW engine render(app, { root: path.resolve(this.extensionPath, 'views'), layout: 'template', @@ -82,9 +78,11 @@ export class RevealServer { debug: true }); - const router = new Router(); - router.get('/', async (ctx, next) => { + + // MAIN FILE + app.use( async (ctx, next) => { + if(ctx.path !== '/') { return next()} const htmlSlides = this.getSlides().map(s => ( { @@ -92,16 +90,24 @@ export class RevealServer { html: markdown.render(s.text), children: s.verticalChildren.map(c => ( {...c, html: markdown.render(c.text) })) })) - ctx.state = { slides: htmlSlides, ...this.getConfiguration() } await ctx.render('reveal'); }); + + // STATIC LIBS const libsPAth = path.join(this.extensionPath, 'libs') - router.get('/libs', koastatic(libsPAth)); - - app.use(router.routes()); + app.use(serve({ rootDir:libsPAth, rootPath: '/libs' })) + + // STATIC RELATIVE TO MD FILE + const rootDir = this.getRootDir() + if (rootDir) { + app.use(serve({rootDir, rootPath : '/' })) + } + + + // ERROR HANDLER app.on('error', err => { this.logger.error(err) })