@eik/common
Advanced tools
Comparing version 3.0.0-next.1 to 4.0.0-next.1
@@ -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 @@ |
@@ -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", |
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
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
40171
908
19