15.14.4 • Published 8 years ago

ft-next-express v15.14.4

Weekly downloads
769
License
-
Repository
-
Last release
8 years ago

next-express Circle CI

Slightly enhanced Express.

npm install -S ft-next-express

Comes with:-

  • Handlebars (with added support for loading partials from bower_components)
  • Origami Image Service integration
  • Sensible error handling (configurable via environment variables)
  • Full Next Flags integration
  • Next Metrics integration
    • measures sytem performance
    • measures performance of service dependencies (if called using the fetch api)
    • measures request and response performance
    • exposes the configured metrics instance as express.metrics
  • Anti-search engine GET /robots.txt (possibly might need to change in the future)
  • (Isomorphic) Fetch polyfill
  • Exposes everything in the app's ./public folder via ./{{name-of-app}} (only in non-production environments, please use next-assets or hashed-assets in production)
  • Exposes app name via __name to templates and in a data-next-app attribute on the html tag in templates
  • Adds a /{{name-of-app}}/__about endpoint, which exposes information about the current version of the application running
  • By default the application's templates are outputted unchanged, but ft-next-express provides 2 inheritable layouts

  • Exposes express.Router

  • Provides NODE_ENV to templates via __environment
  • __isProduction is true if NODE_ENV equals PRODUCTION (exposed as data-next-is-production on the <html> tag in templates)
  • __version is set to the same value as that used by next-build-tools/about (exposed as data-next-version on the <html> tag in templates)
  • Provides a range of handlebars helpers, including template inheritance and layouts
  • instruments fetch to send data about server-to-server requests to graphite. See main.js for a list of services already instrumented. To add more services extend the list or, for services specific to a particular app, pass in a 'serviceDependencies' option (see examples below)
  • Provides a solution for implementing app health checks in adherence to the FT Health Check Standard
  • Logging (Next logger), exposed via express.logger

Installation

npm install --save ft-next-express

Example app

main.js

var express = require('ft-next-express');

var app = express({

	// Optional.  If name is not provided, next-express will try to infer it from package.json
	name: "xian",

	// Optional
	helpers: {
		uppercase: function(options) {
			return options.fn(this).toUpperCase();
		}
	},
	serviceDependencies: {
		// service dependencies should be listed with a regex that matches urls for that service.
		// regexes can be whatever you like so it's possible to treat paths within a given service
		// as separate services
		'youtube': /https?:\/\/youtube\.com/
	},
	// the following default to true but should normally be set to false if your app is an api
	withFlags: false, // disable feature flag middleware
	withHandlebars: false // disable handlebars middleware
	withBackendAuthentication: false // disable authentication which only allows requests in via fastly

	// Optional
	healthChecks: []
});

app.get('/', function(req, res, next) {
	res.render('main', {
		title: "FT",
		image: "https://avatars0.githubusercontent.com/u/3502508?v=3",
		date: new Date(),
		text : "<p>This wont be shown</p><p>This will be shown</p><p>This wont be shown</p>"
	});
});

app.listen(process.env.PORT, function() {
	console.log("Listening on " + process.env.PORT);
});

views/main.html

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>{{title}}</title>
	<!-- this will be output as <link rel="stylesheet" href="/xian/main.css"> -->
	<link rel="stylesheet" href="/{{__name}}/main.css">
</head>
<body>
	<h1>{{title}}</h1>
	{{#uppercase}}this text will be uppercase{{/uppercase}}
	<h2>An image resized to 150px wide</h2>
	<img src="{{#resize 150}}{{image}}{{/resize}}" />

	{{#flags.myFlag}}
	The 'myFlag' flag is switched on
	{{/flags.myFlag}}

	<time data-o-component="o-date" class="o-date" datetime="{{#dateformat}}{{date}}{{/dateformat}}">
		{{#dateformat "dddd, d mmmm, yyyy"}}{{date}}{{/dateformat}}
	</time>

	{{paragraphs text start=1 end=2}}

	{{#removeImageTags}}
	Image<img src="someimage.jpg" alt="This wont be shown"/>EndImage
	{{/removeImageTags}}
</body>
</html>

Testing flags

If you’re using flags and testing with mocha, you’ll need to expose listen in your app:

module.exports.listen = app.listen(port);

And in your tests, add this:

before(function() {
	return app.listen;
});

This’ll make sure your tests wait for flags to be ready.

Health checks

For an example set of health check results, see next.ft.com/__health. For testing health checks, the Health Status Formatter extension for Google Chrome is recommended.

Health checks can be tested for failures of a specific degree of severity by appending the severity number to the health check URL. This is particularly useful for setting up fine-grained alerting. For example, if on next.ft.com a severity level 2 health check were failing:

https://next.ft.com/__health.1 would return HTTP status 200 https://next.ft.com/__health.2 would return HTTP status 500 https://next.ft.com/__health.3 would return HTTP status 500

Each health check must have a getStatus() property, which returns an object meeting the specifications of the FT Health Check Standard and the FT Check Standard. This might look roughly like the following example:

var exampleHealthCheck = {
	getStatus: () => {
		return {
			name: 'Some health check',
			ok: true,
			checkOutput: 'Everything is fine',
			lastUpdated: new Date(),
			panicGuide: 'Don\'t panic',
			severity: 3,
			businessImpact: "Some specific feature will fail",
			technicalSummary: "Doesn\'t actually check anything, just an example"
		};
	}
}
15.14.4

8 years ago

15.14.3

8 years ago

15.14.1

8 years ago

15.14.0

8 years ago

15.13.0

8 years ago

15.12.1

8 years ago

15.12.0

8 years ago

15.11.3

8 years ago

15.11.2

8 years ago

15.11.1

8 years ago

15.11.0

8 years ago

15.10.1

8 years ago

15.10.0

8 years ago

15.9.0

8 years ago

15.8.0

8 years ago

15.7.2

8 years ago

15.7.1

8 years ago

15.7.0

8 years ago

15.6.1

8 years ago

15.6.0

8 years ago

15.5.0

8 years ago

15.4.7

8 years ago

15.4.6

9 years ago

15.4.5

9 years ago

15.4.3

9 years ago

15.4.2

9 years ago

15.4.1

9 years ago

15.4.0

9 years ago

15.3.9

9 years ago

15.3.8

9 years ago

15.3.7

9 years ago

15.3.6

9 years ago

15.3.5

9 years ago

15.3.4

9 years ago

15.3.3

9 years ago

15.3.1

9 years ago

0.0.1

9 years ago

15.3.0

9 years ago

15.2.0

9 years ago

15.1.0

9 years ago

15.0.0

9 years ago

14.2.3

9 years ago

14.2.2

9 years ago

14.2.1

9 years ago

14.2.0

9 years ago

14.1.4

9 years ago

14.1.3

9 years ago

14.1.2

9 years ago

14.1.1

9 years ago

14.1.0

9 years ago

14.0.4

9 years ago

14.0.3

9 years ago

14.0.2

9 years ago

14.0.1

9 years ago

14.0.0

9 years ago

13.8.0

9 years ago

13.7.2

9 years ago

13.7.1

9 years ago

13.7.0

9 years ago

13.6.0

9 years ago

13.5.3

9 years ago

13.5.2

9 years ago

13.4.0

9 years ago

13.3.4

9 years ago

13.3.3

9 years ago

13.3.2

9 years ago

13.3.1

9 years ago

13.3.0

9 years ago

13.2.1

9 years ago

13.2.0

9 years ago

13.1.2

9 years ago

13.1.1

9 years ago

13.1.0

9 years ago

13.0.1

9 years ago

13.0.0

9 years ago

12.13.1

9 years ago

12.13.0

9 years ago

12.12.0

9 years ago

12.11.0

9 years ago

12.10.1

9 years ago

12.10.0

9 years ago

12.9.1

9 years ago

12.9.0

9 years ago

12.8.1

9 years ago

12.8.0

9 years ago

12.7.0

9 years ago

12.6.4

9 years ago

12.6.3

9 years ago

12.5.0

9 years ago

12.4.0

9 years ago

12.3.2

9 years ago

12.2.0

9 years ago

12.1.1

9 years ago

12.1.0

9 years ago

12.0.0

9 years ago

11.5.0

9 years ago

11.4.4

9 years ago

11.4.3

9 years ago

11.4.2

9 years ago

11.4.1

9 years ago

11.4.0

9 years ago

11.3.4

9 years ago

11.3.3

9 years ago

11.3.2

9 years ago

11.3.1

9 years ago

11.3.0

9 years ago

11.2.2

9 years ago

11.2.1

9 years ago

11.2.0

9 years ago

11.1.5

9 years ago

11.1.4

9 years ago

11.1.3

9 years ago

11.1.2

9 years ago

11.1.1

9 years ago

11.1.0

9 years ago

11.0.0

9 years ago

10.6.8

9 years ago

10.6.7

9 years ago

10.6.6

9 years ago

10.6.5

9 years ago

10.6.4

9 years ago

10.6.3

9 years ago

10.6.2

9 years ago

10.6.1

9 years ago

10.6.0

9 years ago

10.5.2

9 years ago

10.5.1

9 years ago

10.5.0

9 years ago

10.4.1

9 years ago

10.4.0

9 years ago

10.3.1

9 years ago

10.3.0

9 years ago

10.2.0

9 years ago

10.1.1

9 years ago

10.1.0

9 years ago

10.0.3

9 years ago

10.0.2

9 years ago

10.0.1

9 years ago

10.0.0

9 years ago

9.1.2

9 years ago

9.1.1

9 years ago

9.1.0

9 years ago

9.0.2

9 years ago

9.0.1

9 years ago

9.0.0

9 years ago

8.16.0

9 years ago

8.14.0

9 years ago

8.13.0

9 years ago

8.12.1

9 years ago

8.12.0

9 years ago

8.11.0

9 years ago

8.10.0

9 years ago

8.9.0

9 years ago

8.8.1

9 years ago

8.7.1

9 years ago

8.7.0

9 years ago

8.6.2

9 years ago

8.6.1

9 years ago

8.6.0

9 years ago

8.5.1

9 years ago

8.5.0

9 years ago

8.4.1

9 years ago

8.4.0

9 years ago

8.3.2

9 years ago

8.3.1

9 years ago

8.3.0

9 years ago

8.2.3

9 years ago

8.2.2

9 years ago

8.2.1

9 years ago

8.2.0

9 years ago

8.1.1

9 years ago

8.1.0

9 years ago

8.0.1

9 years ago

8.0.0

9 years ago

7.9.4

9 years ago

7.9.3

9 years ago

7.9.2

9 years ago

7.9.1

9 years ago

7.8.5

9 years ago

7.8.4

9 years ago

0.0.0

9 years ago

7.8.3

9 years ago

7.8.2

9 years ago

7.8.1

9 years ago

7.8.0

9 years ago

7.7.2

9 years ago

7.7.1

9 years ago

7.7.0

9 years ago

7.6.0

9 years ago

7.5.0

9 years ago

7.4.1

9 years ago

7.4.0

9 years ago

7.3.0

9 years ago

7.2.1

9 years ago

7.2.0

9 years ago

7.1.4

9 years ago

7.1.3

9 years ago

7.1.2

9 years ago

7.1.1

9 years ago

7.1.0

9 years ago

7.0.2

9 years ago

7.0.1

9 years ago

7.0.0

9 years ago

6.7.0

9 years ago

6.6.1

9 years ago

6.6.0

9 years ago

6.5.0

9 years ago

6.4.2

9 years ago

6.4.1

9 years ago

6.4.0

9 years ago

6.3.0

9 years ago

6.2.1

9 years ago

6.2.0

9 years ago

6.1.4

9 years ago

6.1.2

9 years ago

6.1.1

9 years ago

6.1.0

9 years ago

6.0.1

9 years ago

6.0.0

9 years ago

5.1.1

9 years ago

5.1.0

9 years ago

5.0.0

9 years ago

4.3.0

9 years ago

4.2.0

9 years ago

4.1.0

9 years ago

4.0.3

9 years ago

4.0.2

9 years ago

4.0.1

9 years ago

4.0.0

9 years ago

3.3.0

9 years ago

3.2.3

9 years ago

3.2.2

9 years ago

3.2.1

9 years ago

3.2.0

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.5.0

9 years ago

2.4.0

9 years ago

2.3.4

9 years ago

2.3.3

9 years ago

2.3.2

9 years ago

2.3.1

9 years ago

2.2.3

9 years ago

2.2.2

9 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.9.2

9 years ago

1.9.0

9 years ago

1.8.0

9 years ago

1.7.0

9 years ago

1.6.0

9 years ago

1.5.0

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago