Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: tutorial: how to make an add-on with user/use-specific behavior #15

Closed
Ivshti opened this issue Sep 14, 2018 · 1 comment
Closed
Assignees

Comments

@Ivshti
Copy link
Member

Ivshti commented Sep 14, 2018

make an add-on that has different behaviors on different URL prefixes

e.g. for a wrapper add-on, it would take the ID of the add-on you wanna wrap in the URL params

e.g. /foo/manifest.json and /bar/manifest.json get handled by the same functions but with different param

@Ivshti
Copy link
Member Author

Ivshti commented Sep 14, 2018

example of a parametrized add-on, w/o the sdk

const express = require('express')
const addon = express()

addon.get('/:someParameter/manifest.json', function (req, res) {
	res.send({
		id: 'org.parametrized.'+req.params.someParameter,
		name: 'add-on for '+req.params.someParameter,
		resources: ['stream'],
		types: ['series'],
	})
})

addon.get('/:someParameter/stream/:type/:id.json', function(req, res) {
	// @TODO do something depending on req.params.someParameter
	res.send({ streams: [] })
})

addon.listen(19999, function() {
	console.log('http://127.0.0.1:19999')
})

What this example is missing, in comparison to building with the SDK:

  • linting of the manifest
  • parsing of extra
  • more convenient API

Also, you can always construct a new SDK instance depending on req.params.someParameter, but that will be expensive in terms of resource usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants