@financial-times/newsletter-signup

4.11.1 • Public • Published

newsletter-signup

Endpoints to sign an email address up to the FT newsletter (and unsubscribe)

npm i -S @financial-times/newsletter-signup

Usage

Import it, and either call .listen(port) directly:

import newsletterSignup from '@financial-times/newsletter-signup';

newsletterSignup.listen(process.env.PORT || 3000);

or .use() it in your own app:

import newsletterSignup from '@financial-times/newsletter-signup';
import express from 'express';

const app = express();
app.use('/middleware/root', newsletterSignup);

Endpoints

POST [/middleware/root]/

Subscribe an email address provided by the POST body parameter email to the mailing list.

If a middleware sets req.newsletterSignupPostNoResponse to a truthy value, this endpoint will not send a response, but instead set res.locals.newsletterSignupStatus to the status string, so a product can render a template if it needs regular form submission instead of AJAX.

GET [/middleware/root]/unsubscribe/:user

Unsubscribe the user id :user from the list. By default, this does not send a response, but sets status variables in res.locals. Products using this middleware are responsible for rendering a response, by attaching a route to the same path:

app.use('/middleware/root', newsletterSignup);
app.get('/middleware/root/unsubscribe/:user', (req, res) => {
	res.render('unsubscribe');
});

Status template variables

The variables success, alreadyUnsubscribed and failure are available in res.locals and so any templates rendered in this response. They are mutually-exclusive booleans, i.e. exactly one of them will be true.

Environment vars

The (self-explanatory) environment variables ANON_EMAIL_SVC_API_KEY and ANON_EMAIL_LIST_API_KEY are required. There's also the optional variables ANON_EMAIL_SVC_HOST and ANON_EMAIL_LIST_HOST to configure the hostnames to talk to for these services.


Originally part of next-signup.

Readme

Keywords

none

Package Sidebar

Install

npm i @financial-times/newsletter-signup

Weekly Downloads

7

Version

4.11.1

License

MIT

Last publish

Collaborators

  • robgodfrey
  • robertboulton
  • seraph2000
  • hamza.samih
  • notlee
  • emmalewis
  • aendra
  • the-ft
  • rowanmanning
  • chee
  • alexwilson