Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Administrator
m4lab_landing_page
Commits
6fb8ecd4
Commit
6fb8ecd4
authored
Mar 19, 2020
by
Rosanny Sihombing
Browse files
handle 404 and 500 pages
parent
9a611a58
Changes
5
Show whitespace changes
Inline
Side-by-side
app.js
View file @
6fb8ecd4
...
...
@@ -58,12 +58,24 @@ app.use(function(req, res, next) {
next
();
});
//require('./routes/routes')(app, config, passport, i18n);
require
(
'
./routes/routes-account
'
)(
app
,
config
,
passport
,
i18n
);
require
(
'
./routes/routes-project
'
)(
app
,
config
,
passport
);
//require('./routes/dbconn')(app, config);
require
(
'
./routes/api
'
)(
app
,
config
,
passport
);
// Handle 404
app
.
use
(
function
(
req
,
res
,
next
)
{
//res.status(404).send('404: Page not Found', 404)
res
.
status
(
404
).
render
(
'
./DE/404
'
)
})
// Handle 500 - any server error
app
.
use
(
function
(
err
,
req
,
res
,
next
)
{
console
.
error
(
err
.
stack
)
res
.
status
(
500
).
render
(
'
./DE/500
'
,
{
error
:
err
})
})
app
.
listen
(
app
.
get
(
'
port
'
),
function
()
{
console
.
log
(
'
Express server listening on port
'
+
app
.
get
(
'
port
'
));
});
\ No newline at end of file
routes/routes-account.js
View file @
6fb8ecd4
...
...
@@ -108,10 +108,6 @@ module.exports = function (app, config, passport, i18n) {
}
});
app
.
get
(
'
/error
'
,
function
(
req
,
res
)
{
res
.
render
(
lang
+
'
/error
'
)
});
app
.
get
(
'
/login
'
,
passport
.
authenticate
(
config
.
passport
.
strategy
,
{
...
...
@@ -272,7 +268,10 @@ module.exports = function (app, config, passport, i18n) {
// Load hashed passwd from DB
dbconn
.
user
.
query
(
'
SELECT password FROM credential WHERE user_id=
'
+
userId
,
function
(
err
,
rows
,
fields
)
{
if
(
err
)
{
res
.
redirect
(
'
/500
'
)
//res.redirect('/500')
res
.
status
(
500
).
render
(
lang
+
'
/500
'
,
{
error
:
err
})
throw
err
}
var
userPwd
=
rows
[
0
].
password
...
...
@@ -280,7 +279,10 @@ module.exports = function (app, config, passport, i18n) {
// check if the password is correct
bcrypt
.
compare
(
currPwd
,
userPwd
,
function
(
err
,
isMatch
)
{
if
(
err
)
{
res
.
redirect
(
'
/500
'
)
//res.redirect('/500')
res
.
status
(
500
).
render
(
lang
+
'
/500
'
,
{
error
:
err
})
throw
err
}
else
if
(
!
isMatch
)
{
...
...
views/DE/404.pug
View file @
6fb8ecd4
extends error
block content
h2 Cannot find #{url}
\ No newline at end of file
doctype html
html(lang="de")
head
title= "404 - Page not found"
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no")
link(rel="stylesheet", type="text/css", href="https://transfer.hft-stuttgart.de/css/bootstrap/bootstrap.css")
style.
.container {
height: 400px;
position: relative;
}
.center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
body
div(class="container")
div(class="center", align="center")
a(href="https://m4lab.hft-stuttgart.de")
img(src="https://transfer.hft-stuttgart.de/images/demo/m4lab_logo.jpg", class="img-responsive center-block", width="185", height="192")
br
br
p 404. The requested URL was not found.
// Bootstrap
script(src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous")
\ No newline at end of file
views/DE/500.pug
View file @
6fb8ecd4
extends error
block content
h1 Error: #{error.message}
if settings['verbose errors']
pre= error.stack
else
p An error ocurred!
\ No newline at end of file
doctype html
html(lang="de")
head
title= "500 - Internal Server Error"
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no")
link(rel="stylesheet", type="text/css", href="https://transfer.hft-stuttgart.de/css/bootstrap/bootstrap.css")
style.
.container {
height: 400px;
position: relative;
}
.center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
body
div(class="container")
div(class="center", align="center")
a(href="https://m4lab.hft-stuttgart.de")
img(src="https://transfer.hft-stuttgart.de/images/demo/m4lab_logo.jpg", class="img-responsive center-block", width="185", height="192")
br
br
p 500. Unexpected Error :(
p #{ error }
// Bootstrap
script(src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous")
\ No newline at end of file
views/DE/error.pug
deleted
100644 → 0
View file @
9a611a58
html
head
title Error
body
h1 An error occurred!
block content
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment