Skip to main content

Expose

@klotho::expose

Specified on a resource to expose that resource to the public.

Supported Libraries

Annotate an Express listen call to enable. Note that you must provide a target = "public" directive, as described below.

Currently supports routes specified on the express.Express object itself:

const express = require('express');
const app = express();

app.get('/', async (req, res) => { res.send("Hello from klotho!") });

/* @klotho::expose {
* target = "public"
* id = "gateway"
* }
*/
app.listen(3000);

exports.app = app;

Or, on middleware:

const router = express.Router();

router.get('/hello', async (req, res) => { res.send(`Hello ${req.body.user}`) })

app.use(router);

/* @klotho::expose {
* target = "public"
* id = "gateway"
* }
*/
app.listen(3000);

exports.app = app;

Setup

For middleware and other setup that require an asynchronous process, the application may also be a Promise.

async function setupApp() {
const app = express();
app.use(await createMyMiddleware());
// setup routes, etc
return app;
}

const app = setupApp();

app.then(app => app.listen(3000));

exports.app = app;

Directives

DirectiveTypeDescription
idstring(Required) The exposed endpoint's id. Changing this results in a new endpoint (URL).
targetstring(Required) Must be set and the only allowed value is "public"

Providers