GithubHelp home page GithubHelp logo

gustavnikolaj / express-jsxtransform Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 2.0 32 KB

Express middleware that transforms jsx on the way out.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

express-jsxtransform's People

Contributors

fer8a avatar gustavnikolaj avatar munter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

munter fer8a

express-jsxtransform's Issues

Too eager to send out headers

I think we need to hide the contents of this middleware behind a file extension check. I am getting this problem on a standard webpage, single index.html, single main.css and jquery:

✗ munter at pollex in ~/temp
$ livestyle -r app/ -p 9000 --autoprefixer --jsxtransform
Serving static files from /home/munter/temp/app
Listening to http://0.0.0.0:9000/
   info  - socket.io started

http.js:689
    throw new Error('Can\'t set headers after they are sent.');
          ^
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (http.js:689:11)
    at ServerResponse.res.setHeader (/home/munter/git/livestyle/node_modules/express/node_modules/connect/lib/patch.js:59:22)
    at ServerResponse.<anonymous> (/home/munter/git/livestyle/node_modules/express-autoprefixer/lib/autoprefixer.js:40:25)
    at ServerResponse.emit (events.js:92:17)
    at /home/munter/git/livestyle/node_modules/express-processimage/node_modules/express-hijackresponse/lib/index.js:118:34
    at process._tickCallback (node.js:419:13)

If I remove the --jsxtransform enabler things work out as expected:

✗ munter at pollex in ~/temp
$ livestyle -r app/ -p 9000 --autoprefixer
Serving static files from /home/munter/temp/app
Listening to http://0.0.0.0:9000/
   info  - socket.io started

Forcing Content-Type to text/javascript

While upgrading dependencies and testing one of our systems I found all calls were returning a Content-Type of text/javascript. The jsxtransform middleware appears to be doing this to all requests:

            intercept: function (body, send) {
                var annotationInserted = false;

                if (res.statusCode === 200) {

                // ...

                    res.setHeader('Content-Type', 'text/javascript');
                    res.setHeader('Content-Length', Buffer.byteLength(body));
                    send(body);
                }

Am I missing something, or is this a bug?

doesn't use latest React tools

Partial solution:
I have modified module.json to depend on v.0.13.1 of react-tools and things sort of work ok for me now. It looks like it's just the changes in syntax making some tests fail during npm install:

  1. test server with jsxtransform should transform a js file with jsx content and jsx annotation
  2. test server with jsxtransform should transform a jsx file with jsx content and no jsx annotation
  3. test server with jsxtransform should transform a jsx file with jsx content and jsx annotation

Thanks
J.

The future of express-jsxtransform

As I was made aware in Munter/generator-greenfield#3 facebook no longer uses the jsxtransform module, but babel for their jsx transpilation needs.

I'm no longer using this module myself, but I'll be happy to make changes to it, to move it forward. I just need some advice from actual users.

Would it make sense, to just wrap babel and use that for transpilation of just JSX - if it is even possible to configure babel to do that - or would a full blown babel transpiler be called for? Does it even make sense to do that?

I would love some suggestions on how to move it forward.

/cc @Munter

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.