cmartin81 / decorator-wrap Goto Github PK
View Code? Open in Web Editor NEWA ES6 decorator for wrapping classes or methods with you own custom code. You can easily edit the input and the output
A ES6 decorator for wrapping classes or methods with you own custom code. You can easily edit the input and the output
Hi @cmartin81, @sierra-m ,
I am trying to use decorative wrapper in my rest server with node + express, I am trying to create an auth filter that will take a JWT token for all the rest endpoints and de-tokenize it and send the payload back to the method.
I have created a plugin similar to log, mentioned in the readme file. PFB
`var wrap = require('decorator-wrap').wrap;
var log = function (callback, args, name, type){
console.log('Starting ', type, name);
var result = callback();
console.log('Ended: ', name);
return result;
};
module.exports = function(target, key, descriptor) {
return wrap(log)(target, key, descriptor);
}
`
I am importing the plugin in my router as below
`var express = require('express');
var router = express.Router();
var serviceAdapterForSendEmail= require('../ServiceAdapters/SendEmail');
const Post = require("../models/Post")
/* GET home page. */
var request = require('request');
var fs = require('fs');
var log= require('./log');
console.log(log);
@log
router.get('/', function(req, res, next) {
res.send({
"login": "unsuccessful"
});
});
module.exports = router;`
However, when I execute I get the following error
`RestServiceNodeJSForger % npm run start env=local
> [email protected] start /Users/ag33128/CodeBase_Dev/RestServiceNodeJSForger
> node ./bin/www "env=local"
/Users/ag33128/CodeBase_Dev/RestServiceNodeJSForger/routes/index.js:11
@log
^
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/ag33128/CodeBase_Dev/RestServiceNodeJSForger/app.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./bin/www "env=local"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ag33128/.npm/_logs/2021-12-09T02_43_36_713Z-debug.log`
Any Pointers will be helpful
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.