mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-04-17 13:15:47 +00:00
26 lines
789 B
JavaScript
26 lines
789 B
JavaScript
const { promisify } = require('util');
|
|
const readFile = promisify(require('fs').readFile);
|
|
const path = require('path');
|
|
|
|
module.exports = async (req, res, next) => {
|
|
const id = req.hostname.split('.')[0];
|
|
res.locals.id = id;
|
|
|
|
if (req.method.toUpperCase() !== 'GET') {
|
|
return next();
|
|
}
|
|
|
|
// otherwise load up the user json file
|
|
res.locals.user = {
|
|
copyright: '<copyright holders>',
|
|
};
|
|
readFile(
|
|
path.join(__dirname, '..', 'users', `${id}.json`),
|
|
'utf8'
|
|
)
|
|
.then(data => res.locals.user = JSON.parse(data))
|
|
.catch(({code, message}) => {
|
|
if (code !== 'ENOENT') res.code(500).send(`An internal error occurred - open an issue on https://github.com/remy/mit-license with the following information: ${message}`)
|
|
})
|
|
.finally(() => next())
|
|
};
|