Add routes for static assets, redirects and template based content to your Transom server.
$ npm install --save @transom/transom-scaffold
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);
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
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
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
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.