Giter Club home page Giter Club logo

express-expose's Issues

On application start-up: "TypeError: Cannot set property 'expose' of undefined"

My code for requiring expose looks like this:

------------------BEGIN CODE---------------------
var express = require('express')
, expose = require('express-expose')
, program = require('commander')
, cookie = require('cookie')
, routes = require('./routes')
, api = require('./routes/api.js')
, passport = require('passport')
, BasicStrategy = require('passport-http').BasicStrategy
, config = require('config')
;

program
.version('0.0.1')
.option('-t, --test', 'Run as a test')
.parse(process.argv);

var app = module.exports = express.createServer();
------------------END CODE---------------------

The specific line in express-expose.js throwing the error is line 44.

Please see the attached image...
Screen Shot 2013-03-12 at 10 41 02 AM

Support node 0.8.0

Is there any reason that you can't? I was just making an app and I need to send data to the client-side

function string

Hi TJ
express-expose define the following function to create a string representation of objects

function string(obj) {
  if ('function' == typeof obj) {
    return obj.toString();
  } else if (obj instanceof Date) {
    return 'new Date("' + obj + '")';
  } else if (Array.isArray(obj)) {
    return '[' + obj.map(string).join(', ') + ']';
  } else if ('[object Object]' == Object.prototype.toString.call(obj)) {
    return '{' + Object.keys(obj).map(function(key){
      return '"' + key + '":' + string(obj[key]);
    }).join(', ') + '}';
  } else {
    return JSON.stringify(obj);
  }
}

This works well except when used with mongo ObjectId object, where I end up with this serialisation

window.someId = window.someId || {};
someId["_bsontype"] = "ObjectID";
someId["id"] = "OÏ�\u001a¾�Å°U\u0000\u00000";

for my use case, I could replace the Object.prototype.toString statement with obj.toString (toString return string representation on ObjectId)

...
 // else if ('[object Object]' == Object.prototype.toString.call(obj)) {
 else if ('[object Object]' == obj.toString.call(obj)) {

Could the function be exposed somehow so I can inject my customisations ?
Or do you see a better solution for this kind of issues ?

IE8 Bug

For some odd reason, IE8 isn't happy with this:
https://github.com/visionmedia/express-expose/blob/master/lib/express-expose.js#L218

var test = test || {}; causes a problem. I'm guessing it has something to do with hoisting replacing the global variable.

In any case, swapping this,

return (i ? '' : 'var ') + part + ' = ' + part + ' || {};';

with this,

return (i ? '' : 'window.') + part + ' = window.' + part + ' || {};';

gets around the problem. Not sure you want to do that, just thought I'd point it out.

archive this repo?

ref: expressjs/discussions#134

@tj , @niftylettuce - you have been identified as the last / most active committer in this repo which is inactive for a while. This ping is to check with you to determine:

  • whether do you have any specific maintenance plans with this repo
  • are you fine for this repo to be archived
  • do you believe if there is another stake holder / affected party who should know

thanks!

Encoding & ObjectId

When exposing mongoose model I have to explicitly call
model._id.toString() to have the id correctly encoded in the client page
otherwise it get encoded lilke that
Do you have any any better solution to use expose with this kind of object ?

myModel["_id"] = {"id":"N�� \u001fB> 5\u0000\u0000\u0005"};

500 ReferenceError with [email protected], [email protected] and [email protected]

I am getting the following error:

500 ReferenceError: /private/tmp/express-expose/examples/views/index.jade:4 2| head 3| title= settings.title > 4| script!= javascript 5| body Hello javascript is not defined

app.js

/**
 * Module dependencies.
 */

var express = require('express')
  , http = require('http')
  , path = require('path')
  , expose = require('../../express-expose')

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});
app.expose(app.settings);

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', function(req, res) {
  res.render('index', { title: 'Express' });
});

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

index.jade

html
  head
    title= settings.title
    script!= javascript
  body Hello

property 'prototype' of undefined

Cannot read property 'prototype' of undefined
at Object. (/**********/node_modules/express-expose/lib/express-expose.js:51:11)

var secure_keys, 
    express = require("express"),
expose = require("express-expose"), // When I remove this line my app can start:
app = express.createServer(secure_keys); 

node -v:
6.0.13

and npm:

├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected]

node v0.6.x compatibility

Hi, looks like the node version in package.json needs to be modified to be compatible with node v0.6.x

script!= javascript express 3

javascript var isn' t exposed anymore using expose with express 3 ?

creating an app with express command line, adding expose and this line to the template this failed for me

script!= javascript

caching in script files

first off, neat project.

If a project had a large of Javascript that was exposed to the client side (e.g. several modules), would it make sense to have these as "script" includes rather than writing them into the page ?

J

Docs need to mention script!= javascript in setup

Hi guys

Just a quick issue: from a mint express project, this doesn't work with just:

  1. expose = require('express-expose')

  2. app.expose()

    I also had to add:

  3. "script!= javascript" in my jade template

Thanks for this, works beautifully!

node 0.5 compatibility

Heya, is it possible to make express-expose work with node 0.5?

Thanks! :D

$ npm -d install express-expose
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info addNamed [ 'express-expose', '' ]
npm ERR! Error: No compatible version found: express-expose
npm ERR! No valid targets found.
npm ERR! Perhaps not compatible with your version of node?
npm ERR!     at installTargetsError (/opt/local/lib/node_modules/npm/lib/cache.js:424:10)
npm ERR!     at /opt/local/lib/node_modules/npm/lib/cache.js:406:17
npm ERR!     at saved (/opt/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7)
npm ERR!     at Object.cb [as oncomplete] (/opt/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:36:9)
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 11.2.0
npm ERR! command "node" "/opt/local/bin/npm" "-d" "install" "express-expose"
npm ERR! cwd /Volumes/Fuitad/Documents/Dev/
npm ERR! node -v v0.5.10
npm ERR! npm -v 1.0.106
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Volumes/Fuitad/Documents/Dev/npm-debug.log
npm not ok

XSS vulnerable

This module creates content for an inline <script> tag. However, if anything in the content of that script tag includes </script>, HTML5's parsing rules will prematurely end the tag there, allowing for XSS injection.

This module should modify any strings in the returned JSON (for keys or values) that include </script> to be written as </"+"script>.

empty expose should be empty

when app.exposed(name) and res.exposed(name) return empty strings the helper should also return an empty string in line 69-75:

helpers[name] = function(req, res){
  var appjs = app.exposed(name),
      resjs = res.exposed(name);
  if (appjs || resjs) {
    var js = '// app: \n' + appjs;
    js += '// res: \n' + resjs;
    return js;
  } else return "";
};

better api

something like:

res.expose(obj).as('app.settings')
res.expose(obj).as('app.settings').in('head')

Request-level exposure not working.

Couldn't see an existing issue for this, apart from the pull request with the test.

app.get('/', function(req, res) {
  res.expose('var something = true;');
  res.render('index');
});

The JS string printed in the template omits the stuff added at the request level. Using express 3 & expose 0.3.2.

test don't pass on 0.3

Tests are passing on 0.2.x but they are all failing under 0.3.x
Is everything ok on your computer ?

Here is my environment info

$ node -v 
v0.6.19
$ npm ls
├─┬ [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ ├── [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └─┬ [email protected] 
│   └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └─┬ [email protected] 
│   └── [email protected] 
└── [email protected] 

Requiring after express() call

Not sure if it's considered an issue but when require('express-expose') is after var app = require('express')(), there is an error:

TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'expose'

Code example that fails:

express = require('express')
app = express()
require('express-expose')
app.expose

Code example that works:

express = require("express")
require('express-expose')
app = express()
app.expose

It might strike as an odd use case but it happened while porting an app to express3.

Expose mongoose object directly: 'RangeError: Maximum call stack size exceeded'

I'm trying to directly expose a mongoose object within the callback of the mongoose's find method. When calling res.expose(mongooseObject, 'mongooseObjectName') this results in a the following error:

RangeError: Maximum call stack size exceeded

I don't know if this is an error caused by mongoose or by expose. Does anybody know what's happening here and how i could fix it?

Calling expose multiple times

Would be nice if multiple calls to expose used the last in wins approach. It seems that the first call exposing a function or data is persisted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.