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

@targetprocess/assets-service

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@targetprocess/assets-service - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0-rc.1

CHANGELOG.md

17

package.json
{
"name": "@targetprocess/assets-service",
"version": "0.0.2",
"version": "0.1.0-rc.1",
"description": "Service to serve Targetprocess frontend assets.",

@@ -30,5 +30,7 @@ "main": "index.js",

"fast-html-parser": "^1.0.1",
"husky": "^3.1.0",
"jest": "^23.4.1",
"lint-staged": "^9.5.0",
"nodemon": "^1.17.3",
"prettier": "1.13.7",
"prettier": "^1.19.1",
"supertest": "^3.1.0"

@@ -38,3 +40,14 @@ },

"access": "public"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*.js": [
"prettier --write",
"git add"
]
}
}

@@ -15,3 +15,2 @@ const express = require('express');

const parsed = parseInt(param);
return Number.isNaN(parsed) ? 0 : parsed;

@@ -23,3 +22,22 @@ }

const createApp = ({useCdn, cdnUrl, selfUrl, assetsPath, targetprocessUrl, allowCors, mountPath}) => {
const createApp = ({
useCdn,
cdnUrl,
selfUrl,
assetsPath,
targetprocessUrl,
allowCors,
mountPath,
maxAgeOnMatchingAssetsVersion,
assetsBuildVersion
}) => {
function applyCacheHeader(req, res) {
if (!maxAgeOnMatchingAssetsVersion || !assetsBuildVersion || req.query.version !== assetsBuildVersion) {
res.set('Cache-Control', 'public, max-age=0');
return;
}
res.set('Cache-Control', `private, max-age=${maxAgeOnMatchingAssetsVersion}`);
}
const app = express();

@@ -37,9 +55,21 @@

res.render(`${assetsPath}/board.template.ejs`, {
assetProviderUrl,
tpBaseUrl: targetprocessUrl
const renderOptions = {assetProviderUrl, tpBaseUrl: targetprocessUrl};
res.render(`${assetsPath}/board.template.ejs`, renderOptions, (err, html) => {
if (err) {
return req.next(err);
}
applyCacheHeader(req, res);
res.send(html);
});
});
router.get('*', express.static(assetsPath));
router.get(
'*',
express.static(assetsPath, {
cacheControl: false,
setHeaders(res, path, stat) {
applyCacheHeader(res.req, res);
}
})
);

@@ -46,0 +76,0 @@ app.set('views engine', 'ejs');

4

src/env.js

@@ -14,5 +14,7 @@ const {resolve} = require('path');

TARGETPROCESS_URL: str({default: '../'}),
MOUNT_PATH: str({default: '/'})
MOUNT_PATH: str({default: '/'}),
MAX_AGE_ON_MATCHING_ASSETS_VERSION: num({default: 60 * 60 * 24 * 365}), // 1 year
ASSETS_BUILD_VERSION: str({default: '0.0.23'})
},
{strict: true}
);

@@ -10,7 +10,11 @@ const {createApp} = require('./app');

targetprocessUrl: env.TARGETPROCESS_URL,
mountPath: env.MOUNT_PATH
mountPath: env.MOUNT_PATH,
maxAgeOnMatchingAssetsVersion: env.MAX_AGE_ON_MATCHING_ASSETS_VERSION,
assetsBuildVersion: env.ASSETS_BUILD_VERSION
});
app.listen(env.PORT, () => {
console.log(`Assets service started on ${env.PORT} port.`);
console.log(
`Assets service started on ${env.PORT} port. NODE_ENV: ${env.NODE_ENV}. ASSETS_BUILD_VERSION: ${env.ASSETS_BUILD_VERSION}`
);
});

@@ -220,2 +220,24 @@ const fs = require('fs');

});
it('should support asset caching', async () => {
const app = createApp({
useCdn: false,
selfUrl,
allowCors: true,
assetsPath,
cdnUrl,
targetprocessUrl,
mountPath: '/',
assetsBuildVersion: '0.0.2',
maxAgeOnMatchingAssetsVersion: 3601
});
const response1 = await superTest(app).get(BOARD_TEMPLATE_URL + '?version=0.0.2');
checkSuccess(response1, MimeTypes.HTML);
expect(response1.headers['cache-control']).toBe('private, max-age=3601');
const response2 = await superTest(app).get(BOARD_TEMPLATE_URL + '?version=0.0.3');
checkSuccess(response2, MimeTypes.HTML);
expect(response2.headers['cache-control']).toBe('public, max-age=0');
});
});

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