mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Handled no such file exception
This commit is contained in:
parent
a7e014796a
commit
61c71e6c8d
2 changed files with 105 additions and 25 deletions
|
@ -49,7 +49,7 @@ app.use(bodyParser.json({
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
app.get('/*', function (req, res) {
|
app.get('/*', function (req, res) {
|
||||||
let parsedUrl = req.url.replace(/%20/g, " ")
|
let parsedUrl = req.url.replace(/%20/g, ' ')
|
||||||
let curr = listedFiles + '/' + parsedUrl.substring('/'.length, parsedUrl.length).split('?')[0]
|
let curr = listedFiles + '/' + parsedUrl.substring('/'.length, parsedUrl.length).split('?')[0]
|
||||||
let relPath = curr.substring('./public/files'.length, curr.length)
|
let relPath = curr.substring('./public/files'.length, curr.length)
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ app.get('/*', function (req, res) {
|
||||||
|
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
|
|
||||||
|
try {
|
||||||
if (fs.lstatSync(curr).isDirectory()) {
|
if (fs.lstatSync(curr).isDirectory()) {
|
||||||
if (curr[curr.length - 1] !== '/') { curr += '/' }
|
if (curr[curr.length - 1] !== '/') { curr += '/' }
|
||||||
|
|
||||||
|
@ -96,6 +97,11 @@ app.get('/*', function (req, res) {
|
||||||
let fileStream = fs.createReadStream(curr)
|
let fileStream = fs.createReadStream(curr)
|
||||||
fileStream.pipe(res)
|
fileStream.pipe(res)
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
res.render('stuff/nofile', {
|
||||||
|
missingFile: curr
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------
|
||||||
|
|
74
views/stuff/nofile.ejs
Normal file
74
views/stuff/nofile.ejs
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<body bgcolor="#212127">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>No such file/folder</title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font: normal 14px Verdana;
|
||||||
|
color: #999999;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
vertical-align: top
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
font: normal 14px Verdana;
|
||||||
|
color: #999999;
|
||||||
|
background-color: #212127;
|
||||||
|
width: 100%;
|
||||||
|
height: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #9999ff;
|
||||||
|
}
|
||||||
|
.subtable {
|
||||||
|
border-collapse: collapse;
|
||||||
|
table-layout:fixed;
|
||||||
|
width:100%
|
||||||
|
}
|
||||||
|
.maintable {
|
||||||
|
border-collapse: collapse;
|
||||||
|
table-layout:fixed;
|
||||||
|
width:100%
|
||||||
|
padding:0; margin:0;
|
||||||
|
border: none !important;
|
||||||
|
}
|
||||||
|
tr {
|
||||||
|
line-height: 29px;
|
||||||
|
width:32%;
|
||||||
|
}
|
||||||
|
.butt {
|
||||||
|
background-color: #212127;
|
||||||
|
color: #999999;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
border: none;
|
||||||
|
text-align: left;
|
||||||
|
outline: none;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active,
|
||||||
|
.butt:hover {
|
||||||
|
background-color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<center>
|
||||||
|
<h1>
|
||||||
|
No such file / folder:
|
||||||
|
</br>
|
||||||
|
<%= missingFile %>
|
||||||
|
</br>
|
||||||
|
<a href="<%= "http://stuff.frylabs.net" %>" > Back to root </a>
|
||||||
|
</h1>
|
||||||
|
</center>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue