Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dp.use("before", (acc, next) => {
console.log("Entity model:MyModel is being called");
next();
});
dp.use("before", (acc, next) => {
console.log("hijacking");
next(null, "hijacked");
});
dp.use("before", (acc, next) => {
console.log("never got here");
next();
});
const MyModel = DataPoint.Model("MyModel", {
value: () => {
// this will not be executed because the entity was hijacked
console.log("processing");
return "hello";
}
});
dp.resolve(MyModel, true)
// console output:
// Entity model:MyModel is being called
// hijacking
.then(value => {
assert.strictEqual(value, "hijacked");
});
const express = require("express");
const DataPoint = require("data-point");
const DataPointService = require("../lib");
const Model = DataPoint.Model("HelloWorld", {
value: (input, acc) => {
const person = acc.locals.query.person;
if (!person) {
throw new Error(
'Url query parameter "person" is missing. Try appending ?person=Darek at the end of the URL'
);
}
return `Hello ${person}!!`;
},
params: {
cache: {
ttl: "30s",
staleWhileRevalidate: "3m"
}
}
});