Restify.createServer({ name: 'Pterodactyl Daemon', certificate: (Config.get('web.ssl.enabled') === true) ? Fs.readFileSync(Config.get('web.ssl.certificate')) : null, key: (Config.get('web.ssl.enabled') === true) ? Fs.readFileSync(Config.get('web.ssl.key')) : null, formatters: { 'application/json': (req, res, body, callback) => { callback(null, JSON.stringify(body, null, 4)); }, }, })
server.use(function packageParser (req, res, next) { if (typeof req.params.namespace !== 'undefined' && req.params.package !== 'undefined') { req.package = { namespace: req.params.namespace, name: req.params.package, id: `${req.params.namespace}/${req.params.package}` }; req.log.debug({package: req.package}, 'request package information'); } return next(); });
// Log errors server.on('uncaughtException', function(req, res, route, err) { // TODO // We should pipe our errors in graylog here console.log(req.body, res.body, route, err); return false; });
start() { server.listen(PORT, () => { logger.info(`Server started: http://localhost:${PORT}`); }); }
const start = port => new Promise((resolve, reject) => { server.listen(port, err => { return err ? reject(err) : resolve(server); }); })
// Listen for incoming requests. server.post('/api/messages', (req, res) => { adapter.processActivity(req, res, async (context) => { // Route theincoming activity to the main bot turn handler. await bot.onTurn(context); }); });
// last server config server.on('after', restifyBunyanLogger({ // Let's not show the calls on /status skip: function(req) { return req.url === "/status" || req.method === "OPTIONS"; } }));
// Authentication middleware - we place it in each controller because some content may not need authentication routerInstance.use(function (req, res, next) { auth.findByToken(req.headers['x-access-token'], function (code, result) { if (code === 200) { return next(); } else { return next(new errs.UnauthorizedError()); } }); });