DTP Base provides a scalable and secure Node.js application development harness ready for production service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
1.7 KiB

// manifest.js
// Copyright (C) 2022,2023 DTP Technologies, LLC
// All Rights Reserved
'use strict';
const DTP_COMPONENT_NAME = 'manifest';
import { SiteController } from '../../lib/site-controller.js';
export default class ManifestController extends SiteController {
static get name ( ) { return 'ManifestController'; }
static get slug ( ) { return 'manifest'; }
static create (dtp) {
const instance = new ManifestController(dtp);
return instance;
}
constructor (dtp) {
super(dtp, DTP_COMPONENT_NAME);
}
async start ( ) {
const { dtp } = this;
const { limiter: limiterService } = dtp.services;
const router = this.createRouter('/manifest.json');
router.use(async (req, res, next) => {
res.locals.currentView = DTP_COMPONENT_NAME;
return next();
});
router.get('/',
limiterService.create(limiterService.config.manifest.getManifest),
this.getManifest.bind(this),
);
}
async getManifest (req, res, next) {
try {
const manifest = {
id: '/',
scope: '/',
start_url: '/',
name: this.dtp.config.site.name,
short_name: this.dtp.config.site.name,
description: this.dtp.config.site.description,
display: 'fullscreen',
theme_color: '#62767e',
background_color: '#62767e',
icons: [ ],
};
[512, 384, 256, 192, 144, 96, 72, 48, 32, 16].forEach((size) => {
manifest.icons.push({
src: `/img/icon/icon-${size}x${size}.png`,
sizes: `${size}x${size}`,
type: 'image/png'
});
});
res.status(200).json(manifest);
} catch (error) {
return next(error);
}
}
}