29 lines
908 B
TypeScript
29 lines
908 B
TypeScript
import { Request, Response, Router } from 'express';
|
|
import { landingTemplate } from '../landingTemplate';
|
|
import { buildManifest, getDefaultConfig } from '../utils';
|
|
import { Source } from '../source';
|
|
import { Config } from '../types';
|
|
|
|
export class ConfigureController {
|
|
public readonly router: Router;
|
|
|
|
private readonly sources: Source[];
|
|
|
|
constructor(sources: Source[]) {
|
|
this.router = Router();
|
|
|
|
this.sources = sources;
|
|
|
|
this.router.get('/configure', this.getConfigure.bind(this));
|
|
this.router.get('/:config/configure', this.getConfigure.bind(this));
|
|
}
|
|
|
|
private readonly getConfigure = (req: Request, res: Response) => {
|
|
const config: Config = JSON.parse(req.params['config'] || JSON.stringify(getDefaultConfig()));
|
|
|
|
const manifest = buildManifest(this.sources, config);
|
|
|
|
res.setHeader('content-type', 'text/html');
|
|
res.send(landingTemplate(manifest));
|
|
};
|
|
}
|