Comparing version 0.3.0 to 1.0.0
33
index.js
@@ -5,2 +5,3 @@ module.exports = MiddlewareBase => class SPA extends MiddlewareBase { | ||
} | ||
optionDefinitions () { | ||
@@ -19,6 +20,12 @@ return [ | ||
typeLabel: '{underline RegExp}', | ||
description: 'A regular expression to identify an asset file. Defaults to "\\.".' | ||
description: 'A regular expression to identify an asset file. Defaults to "\\.", meaning the server will only read from disk if the requested path contains a ".". This option is more efficient than `spa.asset-test-fs`.' | ||
}, | ||
{ | ||
name: 'spa.asset-test-fs', | ||
type: Boolean, | ||
description: 'Use the filesystem to identify an asset file. If the file exists on disk, serve it else return the SPA. If specified, `spa.asset-test` will be ignored. This option is less efficient but more reliable than `spa.asset-test`.' | ||
} | ||
] | ||
} | ||
middleware (options) { | ||
@@ -28,9 +35,19 @@ const spa = options.spa | ||
const path = require('path') | ||
const send = require('koa-send') | ||
const _ = require('koa-route') | ||
const root = path.resolve(options.directory || process.cwd()) | ||
const assetTest = new RegExp(options.spaAssetTest || '\\.') | ||
this.emit('verbose', 'middleware.spa.config', { spa, root, assetTest }) | ||
return _.get('*', (ctx, route, next) => { | ||
if (ctx.accepts('text/html') && !assetTest.test(route)) { | ||
this.emit('verbose', 'middleware.spa.config', { spa, root, spaAssetTest: options.spaAssetTest, spaAssetTestFs: options.spaAssetTestFs }) | ||
return function (ctx, next) { | ||
const route = ctx.request.url | ||
let isStatic | ||
if (options.spaAssetTest) { | ||
const re = new RegExp(options.spaAssetTest) | ||
isStatic = re.test(route) | ||
} else if (options.spaAssetTestFs && route !== '/') { | ||
const fs = require('fs') | ||
const filePath = path.join(root, route) | ||
isStatic = fs.existsSync(filePath) | ||
} else { | ||
isStatic = /\./.test(route) | ||
} | ||
if (ctx.accepts('text/html') && !isStatic) { | ||
const send = require('koa-send') | ||
return send(ctx, spa, { root }) | ||
@@ -40,5 +57,5 @@ } else { | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "lws-spa", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "Middleware adding support for Single Page Applications to lws", | ||
@@ -14,17 +14,22 @@ "repository": "https://github.com/lwsjs/spa.git", | ||
"engines": { | ||
"node": ">=7.6" | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "test-runner test/*.js" | ||
"test": "test-runner test/*.js", | ||
"cover": "nyc npm test && nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
"dependencies": { | ||
"koa-route": "^3.2.0", | ||
"koa-send": "^4.1.3" | ||
"koa-send": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"lws": "^1.2.1", | ||
"lws-static": "^0.4.1", | ||
"req-then": "^0.6.4", | ||
"test-runner": "^0.5.0" | ||
} | ||
"coveralls": "^3.0.3", | ||
"lws": "^1.3.1", | ||
"lws-static": "^0.5.0", | ||
"node-fetch": "^2.6.0", | ||
"nyc": "^14.1.1", | ||
"test-runner": "^0.6.0" | ||
}, | ||
"files": [ | ||
"index.js" | ||
] | ||
} |
[![view on npm](https://img.shields.io/npm/v/lws-spa.svg)](https://www.npmjs.org/package/lws-spa) | ||
[![npm module downloads](https://img.shields.io/npm/dt/lws-spa.svg)](https://www.npmjs.org/package/lws-spa) | ||
[![Build Status](https://travis-ci.org/lwsjs/spa.svg?branch=master)](https://travis-ci.org/lwsjs/spa) | ||
[![Dependency Status](https://david-dm.org/lwsjs/spa.svg)](https://david-dm.org/lwsjs/spa) | ||
[![Dependency Status](https://badgen.net/david/dep/lwsjs/spa)](https://david-dm.org/lwsjs/spa) | ||
[![Coverage Status](https://coveralls.io/repos/github/lwsjs/spa/badge.svg)](https://coveralls.io/github/lwsjs/spa) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard) | ||
@@ -13,2 +14,2 @@ | ||
© 2016-18 Lloyd Brookes <75pound@gmail.com>. | ||
© 2016-19 Lloyd Brookes <75pound@gmail.com>. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
1
15
4794
6
4
55
2
+ Addedkoa-send@5.0.1(transitive)
- Removedkoa-route@^3.2.0
- Removedany-promise@1.3.0(transitive)
- Removeddebug@2.6.9(transitive)
- Removedisarray@0.0.1(transitive)
- Removedkoa-route@3.2.0(transitive)
- Removedkoa-send@4.1.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedms@2.0.0(transitive)
- Removedmz@2.7.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedpath-to-regexp@1.9.0(transitive)
- Removedthenify@3.3.1(transitive)
- Removedthenify-all@1.6.0(transitive)
Updatedkoa-send@^5.0.0