Back to topic list

App

Enduro utilizes the power of generating static files to get the unbelievable performance and simplicity. However, it also enabled developers to either develop api endpoints or even generate endpoint pages dynamically.

app.js file

enduro will include app/app.js file upon starting the server. The file looks like this:

var local_app = function () {}

// * ———————————————————————————————————————————————————————— * //
// *     init
// *
// *    gets called upon starting enduro.js production server
// *    @param {express app} app - express app
// *    @return {nothing}
// * ———————————————————————————————————————————————————————— * //
local_app.prototype.init = function (app) {
    // express app available here
    // don't forget these routes will be available on production server server (defaults to localhost:5000)
}

module.exports = new local_app()

You can easily create custom api routes like this:

var local_app = function () {}

// * ———————————————————————————————————————————————————————— * //
// *     init
// *
// *    gets called upon starting enduro.js production server
// *    @param {express app} app - express app
// *    @return {nothing}
// * ———————————————————————————————————————————————————————— * //
local_app.prototype.init = function (app) {
    app.get('/api/get_random_number', function (req, res) {
        res.send(Math.random().toString())
    })
}

module.exports = new local_app()

when you open localhost:5000/api/get_random_number you will get a different number each time, as you would expect.

To create dynamic pages, check out temper. Temper allows you to render your templates with all the global data, but with custom or extended context.

Back to topic list

Shout out to pexels and freepik