web - quick fix
This commit is contained in:
parent
5d13783ed5
commit
7e77b8d0f9
@ -162,8 +162,8 @@ getRoutes = async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// database error
|
// database error
|
||||||
if(authCode.err) {
|
if(typeof authCode.err !== "undefined") {
|
||||||
global['logs'].debug(authCode[1]);
|
global['logs'].debug(authCode.err);
|
||||||
return res.type('json').status(500).end(JSON.stringify({
|
return res.type('json').status(500).end(JSON.stringify({
|
||||||
status: 500,
|
status: 500,
|
||||||
message: [
|
message: [
|
||||||
@ -171,11 +171,11 @@ getRoutes = async () => {
|
|||||||
]
|
]
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else if(rep) {
|
else if(typeof authCode.reply !== "undefined") {
|
||||||
// retrieve apps
|
// retrieve apps
|
||||||
apps = await db.getApps();
|
apps = await db.getApps();
|
||||||
// database error
|
// database error
|
||||||
if(apps.reply) {
|
if(typeof apps.err !== "undefined") {
|
||||||
global['logs'].debug(apps.err);
|
global['logs'].debug(apps.err);
|
||||||
return res.type('json').status(500).end(JSON.stringify({
|
return res.type('json').status(500).end(JSON.stringify({
|
||||||
status: 500,
|
status: 500,
|
||||||
@ -189,7 +189,7 @@ getRoutes = async () => {
|
|||||||
// if app.id is equal to queried app
|
// if app.id is equal to queried app
|
||||||
if(app.id == req.query.id) {
|
if(app.id == req.query.id) {
|
||||||
// redirect to app
|
// redirect to app
|
||||||
return res.redirect(app.access+"?uid="+req.session.user.id+"&token="+rep.token);
|
return res.redirect(app.access+"?uid="+req.session.user.id+"&token="+authCode.reply.token);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,7 +11,7 @@ asyncer = require('express-async-handler');
|
|||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
|
var cfg = require(global['__dirname']+'/bin/config');
|
||||||
|
|
||||||
// reduce IO file checks - save file state in cache
|
// reduce IO file checks - save file state in cache
|
||||||
var fileCheck = (file) => {
|
var fileCheck = (file) => {
|
||||||
@ -48,7 +48,8 @@ let getRoutes = async () => {
|
|||||||
apps = await db.getApps();
|
apps = await db.getApps();
|
||||||
res.render('index', {
|
res.render('index', {
|
||||||
session: req.session,
|
session: req.session,
|
||||||
apps: apps.reply
|
apps: apps.reply,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -85,7 +86,8 @@ let getRoutes = async () => {
|
|||||||
res.render('request', {
|
res.render('request', {
|
||||||
session: req.session,
|
session: req.session,
|
||||||
appRequest: req.session.appRequest,
|
appRequest: req.session.appRequest,
|
||||||
apps: apps.reply
|
apps: apps.reply,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
// if user isnt logged in, show login page
|
// if user isnt logged in, show login page
|
||||||
} else {
|
} else {
|
||||||
@ -110,7 +112,7 @@ let getRoutes = async () => {
|
|||||||
* @method all
|
* @method all
|
||||||
* @TODO comments
|
* @TODO comments
|
||||||
*/
|
*/
|
||||||
route.all('/*', (req, res, next) => {
|
route.all('/*', asyncer(async (req, res, next) => {
|
||||||
// passthrough to next route
|
// passthrough to next route
|
||||||
if(req.path.startsWith('/api'))
|
if(req.path.startsWith('/api'))
|
||||||
return next();
|
return next();
|
||||||
@ -135,22 +137,26 @@ let getRoutes = async () => {
|
|||||||
return res.status(404).render('error/404', {
|
return res.status(404).render('error/404', {
|
||||||
error_code: 404,
|
error_code: 404,
|
||||||
error_msg: 'msg.request.file.not_found',
|
error_msg: 'msg.request.file.not_found',
|
||||||
session: req.session
|
session: req.session,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
} else if(rule.type == "missing_permission") {
|
} else if(rule.type == "missing_permission") {
|
||||||
return res.status(401).render('error/permission', {
|
return res.status(401).render('error/permission', {
|
||||||
error_code: 401,
|
error_code: 401,
|
||||||
session: req.session
|
session: req.session,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
} else if(rule.type == "login") {
|
} else if(rule.type == "login") {
|
||||||
return res.status(401).render('error/login', {
|
return res.status(401).render('error/login', {
|
||||||
error_code: 401,
|
error_code: 401,
|
||||||
session: req.session
|
session: req.session,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return res.status(401).render('error/error', {
|
return res.status(401).render('error/error', {
|
||||||
error_code: 401,
|
error_code: 401,
|
||||||
session: req.session
|
session: req.session,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,23 +165,28 @@ let getRoutes = async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if(fileCheck(req.path)) {
|
if(fileCheck(req.path)) {
|
||||||
|
// query apps
|
||||||
|
apps = await db.getApps();
|
||||||
|
|
||||||
return res.render(req.path.replace(/^\//, ''), {
|
return res.render(req.path.replace(/^\//, ''), {
|
||||||
session: req.session,
|
session: req.session,
|
||||||
cfg: global['gds'].cfg
|
apps: apps.reply,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
global['logs'].info("[web] (404) path not found: "+req.path);
|
global['logs'].info("[web] (404) path not found: "+req.path);
|
||||||
return res.status(404).render('error/404', {
|
return res.status(404).render('error/404', {
|
||||||
error_code: 404,
|
error_code: 404,
|
||||||
error_msg: 'msg.request.file.not_found',
|
error_msg: 'msg.request.file.not_found',
|
||||||
session: req.session
|
session: req.session,
|
||||||
|
cfg: cfg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: try to login
|
// TODO: try to login
|
||||||
// TODO: role-based authorization
|
// TODO: role-based authorization
|
||||||
// TODO: show login page or page
|
// TODO: show login page or page
|
||||||
});
|
}));
|
||||||
|
|
||||||
return route;
|
return route;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user