Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cartero-express-middleware

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cartero-express-middleware

Express middleware for Cartero.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

cartero-express-middleware

Express middleware for cartero. Overrides res.render with a method that accepts an additional argument, the path to a parcel.

  • res.locals.cartero_js is populated with the script tags for to load the js for the parcel.
  • res.locals.cartero_css is populated with the link tags for to load the css for the parcel.

The path of the parcel defaults to the directory of the view that is being rendered, so if you use your views folder to hold your parcels as recommended in the cartero docs and tutorial, the variables are set to the appropriate values for parcel of the view being rendered.

Installation

$ npm install cartero-express-middleware

Usage

After runnning cartero, initialize an instance of the cartero node hook, and then install the middleware, passing it the hook instance.

// app.js

var app = express();
var hook = require( "cartero-node-hook" );
var carteroMiddleware = require( "cartero-express-middleware" );
// ...

app.configure( function() {
	app.set( "port" , process.env.PORT || 3000 );
	app.set( "views" , path.join( __dirname, "views" ) );
	app.use( express.static( path.join( __dirname, "static" ) ) );
	// ...

	var h = hook(									// initialize a cartero hook
		path.join( __dirname, "views" ),			// views directory
		path.join( __dirname, "static/assets" ),	// output directory
		{ outputDirUrl : 'assets/' }				// output directory base url
	);

	app.use( carteroMiddleware( h ) );			    // install the middleware

	// ...

	app.get( '/hello', function( req, res ) {
		res.render( 'hello/hello.jade', {}, '/usr/parcels/hello' );
	} );
} );

The middleware sets the res.locals.cartero_js and res.locals.cartero_css properties on res.locals. Templates can then just dump cartero_js and cartero_css to load all the js / css assets they require.

doctype 5
html(lang="en")
    head
        title login
        | !{cartero_js}
        | !{cartero_css} 
    body
        h1 People List
        // ...

Contributors

License

MIT

Keywords

FAQs

Package last updated on 07 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc