Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lws-spa

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lws-spa - npm Package Compare versions

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 @@

&copy; 2016-18 Lloyd Brookes <75pound@gmail.com>.
&copy; 2016-19 Lloyd Brookes <75pound@gmail.com>.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc