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

@eik/common

Package Overview
Dependencies
Maintainers
4
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eik/common - npm Package Compare versions

Comparing version 3.0.0-next.1 to 4.0.0-next.1

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [4.0.0-next.1](https://github.com/eik-lib/common/compare/v3.0.0-next.1...v4.0.0-next.1) (2021-02-19)
### Features
* Add hapi support for local assets ([7528c32](https://github.com/eik-lib/common/commit/7528c3277c537e7e0a4228c949988bc7e7a90074))
# [3.0.0-next.1](https://github.com/eik-lib/common/compare/v2.0.3...v3.0.0-next.1) (2021-02-18)

@@ -2,0 +9,0 @@

46

lib/helpers/local-assets.js

@@ -18,4 +18,4 @@ /* eslint-disable no-await-in-loop */

assert(
app.decorateReply || app.name === 'app',
'App must be an Express or Fastify app instance',
app.decorateReply || app.name === 'app' || app.route,
'App must be an Express, Fastify or Hapi app instance',
);

@@ -30,17 +30,33 @@ assert(

(await eik.mappings()).forEach((mapping) => {
app.get(mapping.destination.url.pathname, (req, res) => {
if (res.set) {
// express
res.set('Access-Control-Allow-Origin', '*');
res.set('content-type', mapping.source.contentType);
fs.createReadStream(mapping.source.absolute).pipe(res);
} else if (res.type) {
// fastify
res.header('Access-Control-Allow-Origin', '*');
res.type(mapping.source.contentType);
res.send(fs.createReadStream(mapping.source.absolute));
}
});
const { pathname } = mapping.destination.url;
const { contentType, absolute: path } = mapping.source;
if (app.get) {
app.get(pathname, (req, res) => {
if (res.set) {
// express
res.set('Access-Control-Allow-Origin', '*');
res.set('content-type', contentType);
fs.createReadStream(path).pipe(res);
} else if (res.type) {
// fastify
res.header('Access-Control-Allow-Origin', '*');
res.type(contentType);
res.send(fs.createReadStream(path));
}
});
} else {
// hapi
app.route({
method: 'GET',
path: pathname,
handler(req, h) {
return h
.response(fs.createReadStream(path))
.header('Access-Control-Allow-Origin', '*')
.type(contentType);
},
});
}
});
}
module.exports = localAssets;
{
"name": "@eik/common",
"version": "3.0.0-next.1",
"version": "4.0.0-next.1",
"description": "Common utilities for Eik modules",

@@ -43,2 +43,3 @@ "main": "lib/index.js",

"devDependencies": {
"@hapi/hapi": "^20.1.0",
"@semantic-release/changelog": "5.0.1",

@@ -45,0 +46,0 @@ "@semantic-release/commit-analyzer": "8.0.1",

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