Skip to content

Commit bceea04

Browse files
refactor(): Move landing and config setup page to router
1 parent 1e8e020 commit bceea04

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/getRouter.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Router = require('router')
22
const qs = require('querystring')
33
const cors = require('cors')
4+
const landingTemplate = require('./landingTemplate')
45

56
const warned = {}
67

@@ -33,8 +34,28 @@ function getRouter({ manifest , get }) {
3334
console.warn('manifest.config is set but manifest.behaviorHints.configurable is disabled, the "Configure" button will not show in the Stremio apps')
3435
}
3536

37+
// landing page
38+
const landingHTML = landingTemplate(manifest)
39+
40+
router.get('/', (_, res) => {
41+
if (hasConfig) {
42+
res.redirect('/configure')
43+
} else {
44+
res.setHeader('content-type', 'text/html')
45+
res.end(landingHTML)
46+
}
47+
})
48+
49+
if (hasConfig) {
50+
router.get('/configure', (_, res) => {
51+
res.setHeader('content-type', 'text/html')
52+
res.end(landingHTML)
53+
})
54+
}
55+
56+
3657
const configPrefix = hasConfig ? '/:config?' : ''
37-
// having config prifix always set to '/:config?' won't resault in a problem for non configurable addons,
58+
// having config prefix always set to '/:config?' won't result in a problem for non-configurable addons,
3859
// since now the order is restricted by resources.
3960

4061
router.get(`${configPrefix}/manifest.json`, manifestHandler)

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module.exports = {
22
addonBuilder: require('./builder'),
33
serveHTTP: require('./serveHTTP'),
44
getRouter: require('./getRouter'),
5+
landingTemplate: require('./landingTemplate'),
56
publishToCentral: require('./publishToCentral'),
67
}

src/serveHTTP.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const express = require('express')
22
const fs = require('fs')
33
const path = require('path')
4-
const landingTemplate = require('./landingTemplate')
54
const getRouter = require('./getRouter')
65
const opn = require('opn')
76

@@ -30,25 +29,6 @@ function serveHTTP(addonInterface, opts = {}) {
3029
app.use(opts.static, express.static(location))
3130
}
3231

33-
const hasConfig = !!(addonInterface.manifest.config || []).length
34-
35-
// landing page
36-
const landingHTML = landingTemplate(addonInterface.manifest)
37-
app.get('/', (_, res) => {
38-
if (hasConfig) {
39-
res.redirect('/configure')
40-
} else {
41-
res.setHeader('content-type', 'text/html')
42-
res.end(landingHTML)
43-
}
44-
})
45-
46-
if (hasConfig)
47-
app.get('/configure', (_, res) => {
48-
res.setHeader('content-type', 'text/html')
49-
res.end(landingHTML)
50-
})
51-
5232
const server = app.listen(opts.port)
5333
return new Promise(function(resolve, reject) {
5434
server.on('listening', function() {

0 commit comments

Comments
 (0)