npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@transomjs/transom-scaffold

v1.2.4

Published

Serve static assets and add redirect routes to a Transom REST API.

Downloads

15

Readme

Transom Scaffold

Add routes for static assets, redirects and template based content to your Transom server.

Build Status Coverage Status

Installation

$ npm install --save @transom/transom-scaffold

Usage

const myApi = require('./myApi');

const Transom = require('@transomjs/transom-core');
const transomScaffold = require('@transomjs/transom-scaffold');
const transom = new Transom();

transom.configure(transomScaffold, {
  scaffold: {
    staticRoutes: [{
      path: /(js|css|fonts|images)\/?.*/,
      folder: 'static-assets'
    }],
    redirectRoutes: [{
        path: '/',
        target: '/login'
      },
      {
        path: '/dummy',
        target: '/login'
      }
    ],
    person: {
      templateName: "Person",
      data: {
        pageTitle: "Person",
        appName: 'Transom Scaffold Demo'
      }
    }  
  }
});

const server = transom.initialize(myApi);

Scaffold options

The options can be passed in to the configure as above, or the scaffold object can be created as a property of the definition object in your Transom configuration. There are two named attributes of scaffold that have special meaning.

staticRoutes

staticRoutes is an Array of Objects used to create GET routes to serve static content. Each entry must include a path and a folder in the application root where static content can be stored. The path can be a regex, or a string and is used to create a new route to files stored in the specified folder. The URL path is combined with the folder path to allow further organizing of static resources.

  scaffold: {
    staticRoutes: [{
      path: /(js|fonts|images)\/?.*/,
      folder: 'static-assets'
    }],
  }

Translates to routes which serve the following files:

  • http://localhost:7000/fonts/comic-sans.ttf  ⇨  /static-assets/fonts/comic-sans.ttf
  • http://localhost:7000/images/logo.png  ⇨  /static-assets/images/logo.png
  • http://localhost:7000/js/bootstrap-select/js/bootstrap-select.js  ⇨  /static-assets/js/bootstrap-select/js/bootstrap-select.js

redirectRoutes

redirectRoutes is an Array of Objects used to create GET routes that redirect to the target. Each entry must include a path which is used to create routes that redirect to the location specified by the target. Target follows the options spec as defined in the Restify.redirect documentation.

  scaffold: {
    redirectRoutes: [{
      path: '/',
      target: '/login'
    },
    {
      path: '/dummy',
      target: {
        pathname: '/foo/bar',
        permanent: true
      }
    }]
  }

Translates to routes which redirect to the following URLs:

  • http://localhost:7000  ⇨  http://localhost:7000/login
  • http://localhost:7000/dummy  ⇨  http://localhost:7000/foobar

Additional Properties

Each additional property of scaffold is used to create a GET route that renders the template identified by templateName. Scaffold uses a template handler such as the one provided by TransomEJSTemplate to load the template and feed it the content of the data attribute.

  scaffold: {
    about: {
      templateName: "NewUserVerify",
        data: {
          pageTitle: "Verify",
          appName: 'Transom Scaffold Demo',
          verifyUrl: '/api/v2/user/verify'
        }
    }
  }

Translates to a route at http://localhost:7000/about that responds with a templated web page, including a title of Verify, an App name of Transom Scaffold Demo etc.

Examples that use this plugin