Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Invalid or unexpected token, Unable to use plugin with express #4

Open
unnisathya92 opened this issue Dec 9, 2021 · 0 comments

Comments

@unnisathya92
Copy link

unnisathya92 commented Dec 9, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant