middleware on res.render() when using a lot of routes
up vote
0
down vote
favorite
I've created a webpage to use it locally. I have a ton of routes like the ones shown below -- 31 .ejs files and 3 .html files. (They are all in the same "views" folder).
//app.js - using node and express
app.get('/page1', function(req, res)
res.render('page1');
);
app.get('/page2', function(req, res)
res.sendFile('views/page2.html', root: __dirname );
);
I use an app.get for each and every one of these files. I've had a feeling it wasn't DRY code, and so now I'm trying to figure out a more elegant and optimal way to achieve the same result.
I know that many
res.sendFile();could be replaced with a singleexpress.static()middleware statement. I usually useexpress.static()on a "public" folder which I use to save all my css files -- like thisapp.use(express.static(path.join(__dirname, 'public')));. But I still don't see how I could use this to simplify all myres.sendFile().As for the many
res.render();routes, I know that if I don't pass any customized data I could probably replace them with a single middleware that handles either a whole directory of template files (and their corresponding routes) or a list of files. I just don't know how I would do that.
Any help is very much appreciated, thanks!!
[UPDATE]
- richie
- node_modules
- public
- css files, images, etc
- views
- partials
- all partial files
- programmingPublic
- all ejs files from a same topic
- other files (html & other ejs)
- appjs
- packagejson
- package-lockjson
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
// Body Parser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded(extended: false));
// engine
app.set("view engine", "ejs");
// Set static path
app.use(express.static(path.join(__dirname, 'public')));
const fs = require('fs');
function renderStatic(dir)
return function(req, res, next)
let target = path.join(dir, req.path);
fs.access(target, fs.constants.R_OK, function(err)
if (err)
// file not found, just move on
next();
else
res.render(target);
);
app.use(renderStatic(path.join(__dirname, "views/programmingPublic")));
Below is the format of my side-menu: (all these files are inside "programmingPublic" folder)
<a href="/programming" class="title">Programming</a>
<li><a href="/c">C</a></li>
<li><a href="/cpp">C++</a></li>
<li><a href="/python">Python</a></li>
<li><a href="/javascript">JavaScript</a></li>
<li><a href="/php">PHP</a></li>
javascript node.js express
|
show 3 more comments
up vote
0
down vote
favorite
I've created a webpage to use it locally. I have a ton of routes like the ones shown below -- 31 .ejs files and 3 .html files. (They are all in the same "views" folder).
//app.js - using node and express
app.get('/page1', function(req, res)
res.render('page1');
);
app.get('/page2', function(req, res)
res.sendFile('views/page2.html', root: __dirname );
);
I use an app.get for each and every one of these files. I've had a feeling it wasn't DRY code, and so now I'm trying to figure out a more elegant and optimal way to achieve the same result.
I know that many
res.sendFile();could be replaced with a singleexpress.static()middleware statement. I usually useexpress.static()on a "public" folder which I use to save all my css files -- like thisapp.use(express.static(path.join(__dirname, 'public')));. But I still don't see how I could use this to simplify all myres.sendFile().As for the many
res.render();routes, I know that if I don't pass any customized data I could probably replace them with a single middleware that handles either a whole directory of template files (and their corresponding routes) or a list of files. I just don't know how I would do that.
Any help is very much appreciated, thanks!!
[UPDATE]
- richie
- node_modules
- public
- css files, images, etc
- views
- partials
- all partial files
- programmingPublic
- all ejs files from a same topic
- other files (html & other ejs)
- appjs
- packagejson
- package-lockjson
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
// Body Parser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded(extended: false));
// engine
app.set("view engine", "ejs");
// Set static path
app.use(express.static(path.join(__dirname, 'public')));
const fs = require('fs');
function renderStatic(dir)
return function(req, res, next)
let target = path.join(dir, req.path);
fs.access(target, fs.constants.R_OK, function(err)
if (err)
// file not found, just move on
next();
else
res.render(target);
);
app.use(renderStatic(path.join(__dirname, "views/programmingPublic")));
Below is the format of my side-menu: (all these files are inside "programmingPublic" folder)
<a href="/programming" class="title">Programming</a>
<li><a href="/c">C</a></li>
<li><a href="/cpp">C++</a></li>
<li><a href="/python">Python</a></li>
<li><a href="/javascript">JavaScript</a></li>
<li><a href="/php">PHP</a></li>
javascript node.js express
In this directory hierarchy, where is__dirname? And, when you have a link like/javascriptin your side-menu, what file are you hoping for that to display? And, where is it?
– jfriend00
Nov 10 at 1:52
I thought__dirnamewas the "richie" folder since it's the root of all files & folders./javascriptis the name of the page -- I save info about the language on it.
– richie
Nov 10 at 1:57
all these files (programming, c, cpp, python, javascript, php) are inside the programmingPublic folder
– richie
Nov 10 at 1:58
Are you trying to render files that have no file extension?
– jfriend00
Nov 10 at 2:01
they are all.ejsfiles. I useapp.set("view engine", "ejs");on the app.js file (like I showed above) and it always works.
– richie
Nov 10 at 2:04
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've created a webpage to use it locally. I have a ton of routes like the ones shown below -- 31 .ejs files and 3 .html files. (They are all in the same "views" folder).
//app.js - using node and express
app.get('/page1', function(req, res)
res.render('page1');
);
app.get('/page2', function(req, res)
res.sendFile('views/page2.html', root: __dirname );
);
I use an app.get for each and every one of these files. I've had a feeling it wasn't DRY code, and so now I'm trying to figure out a more elegant and optimal way to achieve the same result.
I know that many
res.sendFile();could be replaced with a singleexpress.static()middleware statement. I usually useexpress.static()on a "public" folder which I use to save all my css files -- like thisapp.use(express.static(path.join(__dirname, 'public')));. But I still don't see how I could use this to simplify all myres.sendFile().As for the many
res.render();routes, I know that if I don't pass any customized data I could probably replace them with a single middleware that handles either a whole directory of template files (and their corresponding routes) or a list of files. I just don't know how I would do that.
Any help is very much appreciated, thanks!!
[UPDATE]
- richie
- node_modules
- public
- css files, images, etc
- views
- partials
- all partial files
- programmingPublic
- all ejs files from a same topic
- other files (html & other ejs)
- appjs
- packagejson
- package-lockjson
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
// Body Parser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded(extended: false));
// engine
app.set("view engine", "ejs");
// Set static path
app.use(express.static(path.join(__dirname, 'public')));
const fs = require('fs');
function renderStatic(dir)
return function(req, res, next)
let target = path.join(dir, req.path);
fs.access(target, fs.constants.R_OK, function(err)
if (err)
// file not found, just move on
next();
else
res.render(target);
);
app.use(renderStatic(path.join(__dirname, "views/programmingPublic")));
Below is the format of my side-menu: (all these files are inside "programmingPublic" folder)
<a href="/programming" class="title">Programming</a>
<li><a href="/c">C</a></li>
<li><a href="/cpp">C++</a></li>
<li><a href="/python">Python</a></li>
<li><a href="/javascript">JavaScript</a></li>
<li><a href="/php">PHP</a></li>
javascript node.js express
I've created a webpage to use it locally. I have a ton of routes like the ones shown below -- 31 .ejs files and 3 .html files. (They are all in the same "views" folder).
//app.js - using node and express
app.get('/page1', function(req, res)
res.render('page1');
);
app.get('/page2', function(req, res)
res.sendFile('views/page2.html', root: __dirname );
);
I use an app.get for each and every one of these files. I've had a feeling it wasn't DRY code, and so now I'm trying to figure out a more elegant and optimal way to achieve the same result.
I know that many
res.sendFile();could be replaced with a singleexpress.static()middleware statement. I usually useexpress.static()on a "public" folder which I use to save all my css files -- like thisapp.use(express.static(path.join(__dirname, 'public')));. But I still don't see how I could use this to simplify all myres.sendFile().As for the many
res.render();routes, I know that if I don't pass any customized data I could probably replace them with a single middleware that handles either a whole directory of template files (and their corresponding routes) or a list of files. I just don't know how I would do that.
Any help is very much appreciated, thanks!!
[UPDATE]
- richie
- node_modules
- public
- css files, images, etc
- views
- partials
- all partial files
- programmingPublic
- all ejs files from a same topic
- other files (html & other ejs)
- appjs
- packagejson
- package-lockjson
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
// Body Parser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded(extended: false));
// engine
app.set("view engine", "ejs");
// Set static path
app.use(express.static(path.join(__dirname, 'public')));
const fs = require('fs');
function renderStatic(dir)
return function(req, res, next)
let target = path.join(dir, req.path);
fs.access(target, fs.constants.R_OK, function(err)
if (err)
// file not found, just move on
next();
else
res.render(target);
);
app.use(renderStatic(path.join(__dirname, "views/programmingPublic")));
Below is the format of my side-menu: (all these files are inside "programmingPublic" folder)
<a href="/programming" class="title">Programming</a>
<li><a href="/c">C</a></li>
<li><a href="/cpp">C++</a></li>
<li><a href="/python">Python</a></li>
<li><a href="/javascript">JavaScript</a></li>
<li><a href="/php">PHP</a></li>
javascript node.js express
javascript node.js express
edited Nov 10 at 1:36
asked Nov 9 at 22:01
richie
265
265
In this directory hierarchy, where is__dirname? And, when you have a link like/javascriptin your side-menu, what file are you hoping for that to display? And, where is it?
– jfriend00
Nov 10 at 1:52
I thought__dirnamewas the "richie" folder since it's the root of all files & folders./javascriptis the name of the page -- I save info about the language on it.
– richie
Nov 10 at 1:57
all these files (programming, c, cpp, python, javascript, php) are inside the programmingPublic folder
– richie
Nov 10 at 1:58
Are you trying to render files that have no file extension?
– jfriend00
Nov 10 at 2:01
they are all.ejsfiles. I useapp.set("view engine", "ejs");on the app.js file (like I showed above) and it always works.
– richie
Nov 10 at 2:04
|
show 3 more comments
In this directory hierarchy, where is__dirname? And, when you have a link like/javascriptin your side-menu, what file are you hoping for that to display? And, where is it?
– jfriend00
Nov 10 at 1:52
I thought__dirnamewas the "richie" folder since it's the root of all files & folders./javascriptis the name of the page -- I save info about the language on it.
– richie
Nov 10 at 1:57
all these files (programming, c, cpp, python, javascript, php) are inside the programmingPublic folder
– richie
Nov 10 at 1:58
Are you trying to render files that have no file extension?
– jfriend00
Nov 10 at 2:01
they are all.ejsfiles. I useapp.set("view engine", "ejs");on the app.js file (like I showed above) and it always works.
– richie
Nov 10 at 2:04
In this directory hierarchy, where is
__dirname? And, when you have a link like /javascript in your side-menu, what file are you hoping for that to display? And, where is it?– jfriend00
Nov 10 at 1:52
In this directory hierarchy, where is
__dirname? And, when you have a link like /javascript in your side-menu, what file are you hoping for that to display? And, where is it?– jfriend00
Nov 10 at 1:52
I thought
__dirname was the "richie" folder since it's the root of all files & folders. /javascript is the name of the page -- I save info about the language on it.– richie
Nov 10 at 1:57
I thought
__dirname was the "richie" folder since it's the root of all files & folders. /javascript is the name of the page -- I save info about the language on it.– richie
Nov 10 at 1:57
all these files (programming, c, cpp, python, javascript, php) are inside the programmingPublic folder
– richie
Nov 10 at 1:58
all these files (programming, c, cpp, python, javascript, php) are inside the programmingPublic folder
– richie
Nov 10 at 1:58
Are you trying to render files that have no file extension?
– jfriend00
Nov 10 at 2:01
Are you trying to render files that have no file extension?
– jfriend00
Nov 10 at 2:01
they are all
.ejs files. I use app.set("view engine", "ejs"); on the app.js file (like I showed above) and it always works.– richie
Nov 10 at 2:04
they are all
.ejs files. I use app.set("view engine", "ejs"); on the app.js file (like I showed above) and it always works.– richie
Nov 10 at 2:04
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
If you have a bunch of pages that need to call res.render(), but aren't passing custom options to each render, then you could isolate all those templates in their own directory and then use some middleware like this:
const path = require('path');
const fs = require('fs');
function renderStatic(dir, options)
const regex = /^.
app.use(renderStatic(path.join(__dirname, "renderPublic"), ext: ".ejs"));
Note, you must isolate these template files in their own directory so that other files are not found there.
For safety completeness, this code also needs to filter out . and .. items in the path like express.static() does to prevent an attacker from going up your directory hierarchy to get access to other files than those in the render static directory.
Then, for the routes you are using res.sendFile() and no other logic, just isolate those HTML files in their own directory and point express.static() at that directory. Then, the express.static() middleware will find a matching HTML file in that directory and do res.sendFile() for you automatically, exactly the same as it does for your CSS files.
1
@richie - No. Don't addrenderPublicto the HTML page at all. That's local to the server only. That's where you PUT the template files on your server - not anything to do with the public URL for that. Do you understand the difference between the public URL (that the server gets a request for) and the directory that the middleware looks in for a matching file?
– jfriend00
Nov 10 at 0:54
1
@richie - Using the exact code in my answer, you would create a sub-directory under__dirname(where you app is located) and put the template files in there. But, you can obviously put them wherever you want and just pass the right path to them to therenderStatic()middleware so it knows where to look for matches.
– jfriend00
Nov 10 at 0:57
1
@richie - I modified my code so you don't need the.ejson the URLs.
– jfriend00
Nov 10 at 6:00
1
@richie - Notice that my latest version also has the security fix that prevents paths that walk UP the hierarchy with things like./in the path.
– jfriend00
Nov 10 at 6:22
1
@richie - By using an URL like this:/../../../app.js. This would be capable of looking on your hard disk ABOVE therenderPublicdirectory and fetching those files which is not what you want anyone to be able to do. That's why we disable it if there are any leading dots in any path segment.
– jfriend00
Nov 10 at 6:29
|
show 18 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
If you have a bunch of pages that need to call res.render(), but aren't passing custom options to each render, then you could isolate all those templates in their own directory and then use some middleware like this:
const path = require('path');
const fs = require('fs');
function renderStatic(dir, options)
const regex = /^.
app.use(renderStatic(path.join(__dirname, "renderPublic"), ext: ".ejs"));
Note, you must isolate these template files in their own directory so that other files are not found there.
For safety completeness, this code also needs to filter out . and .. items in the path like express.static() does to prevent an attacker from going up your directory hierarchy to get access to other files than those in the render static directory.
Then, for the routes you are using res.sendFile() and no other logic, just isolate those HTML files in their own directory and point express.static() at that directory. Then, the express.static() middleware will find a matching HTML file in that directory and do res.sendFile() for you automatically, exactly the same as it does for your CSS files.
1
@richie - No. Don't addrenderPublicto the HTML page at all. That's local to the server only. That's where you PUT the template files on your server - not anything to do with the public URL for that. Do you understand the difference between the public URL (that the server gets a request for) and the directory that the middleware looks in for a matching file?
– jfriend00
Nov 10 at 0:54
1
@richie - Using the exact code in my answer, you would create a sub-directory under__dirname(where you app is located) and put the template files in there. But, you can obviously put them wherever you want and just pass the right path to them to therenderStatic()middleware so it knows where to look for matches.
– jfriend00
Nov 10 at 0:57
1
@richie - I modified my code so you don't need the.ejson the URLs.
– jfriend00
Nov 10 at 6:00
1
@richie - Notice that my latest version also has the security fix that prevents paths that walk UP the hierarchy with things like./in the path.
– jfriend00
Nov 10 at 6:22
1
@richie - By using an URL like this:/../../../app.js. This would be capable of looking on your hard disk ABOVE therenderPublicdirectory and fetching those files which is not what you want anyone to be able to do. That's why we disable it if there are any leading dots in any path segment.
– jfriend00
Nov 10 at 6:29
|
show 18 more comments
up vote
1
down vote
accepted
If you have a bunch of pages that need to call res.render(), but aren't passing custom options to each render, then you could isolate all those templates in their own directory and then use some middleware like this:
const path = require('path');
const fs = require('fs');
function renderStatic(dir, options)
const regex = /^.
app.use(renderStatic(path.join(__dirname, "renderPublic"), ext: ".ejs"));
Note, you must isolate these template files in their own directory so that other files are not found there.
For safety completeness, this code also needs to filter out . and .. items in the path like express.static() does to prevent an attacker from going up your directory hierarchy to get access to other files than those in the render static directory.
Then, for the routes you are using res.sendFile() and no other logic, just isolate those HTML files in their own directory and point express.static() at that directory. Then, the express.static() middleware will find a matching HTML file in that directory and do res.sendFile() for you automatically, exactly the same as it does for your CSS files.
1
@richie - No. Don't addrenderPublicto the HTML page at all. That's local to the server only. That's where you PUT the template files on your server - not anything to do with the public URL for that. Do you understand the difference between the public URL (that the server gets a request for) and the directory that the middleware looks in for a matching file?
– jfriend00
Nov 10 at 0:54
1
@richie - Using the exact code in my answer, you would create a sub-directory under__dirname(where you app is located) and put the template files in there. But, you can obviously put them wherever you want and just pass the right path to them to therenderStatic()middleware so it knows where to look for matches.
– jfriend00
Nov 10 at 0:57
1
@richie - I modified my code so you don't need the.ejson the URLs.
– jfriend00
Nov 10 at 6:00
1
@richie - Notice that my latest version also has the security fix that prevents paths that walk UP the hierarchy with things like./in the path.
– jfriend00
Nov 10 at 6:22
1
@richie - By using an URL like this:/../../../app.js. This would be capable of looking on your hard disk ABOVE therenderPublicdirectory and fetching those files which is not what you want anyone to be able to do. That's why we disable it if there are any leading dots in any path segment.
– jfriend00
Nov 10 at 6:29
|
show 18 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
If you have a bunch of pages that need to call res.render(), but aren't passing custom options to each render, then you could isolate all those templates in their own directory and then use some middleware like this:
const path = require('path');
const fs = require('fs');
function renderStatic(dir, options)
const regex = /^.
app.use(renderStatic(path.join(__dirname, "renderPublic"), ext: ".ejs"));
Note, you must isolate these template files in their own directory so that other files are not found there.
For safety completeness, this code also needs to filter out . and .. items in the path like express.static() does to prevent an attacker from going up your directory hierarchy to get access to other files than those in the render static directory.
Then, for the routes you are using res.sendFile() and no other logic, just isolate those HTML files in their own directory and point express.static() at that directory. Then, the express.static() middleware will find a matching HTML file in that directory and do res.sendFile() for you automatically, exactly the same as it does for your CSS files.
If you have a bunch of pages that need to call res.render(), but aren't passing custom options to each render, then you could isolate all those templates in their own directory and then use some middleware like this:
const path = require('path');
const fs = require('fs');
function renderStatic(dir, options)
const regex = /^.
app.use(renderStatic(path.join(__dirname, "renderPublic"), ext: ".ejs"));
Note, you must isolate these template files in their own directory so that other files are not found there.
For safety completeness, this code also needs to filter out . and .. items in the path like express.static() does to prevent an attacker from going up your directory hierarchy to get access to other files than those in the render static directory.
Then, for the routes you are using res.sendFile() and no other logic, just isolate those HTML files in their own directory and point express.static() at that directory. Then, the express.static() middleware will find a matching HTML file in that directory and do res.sendFile() for you automatically, exactly the same as it does for your CSS files.
edited Nov 10 at 6:19
answered Nov 9 at 22:56
jfriend00
422k51535583
422k51535583
1
@richie - No. Don't addrenderPublicto the HTML page at all. That's local to the server only. That's where you PUT the template files on your server - not anything to do with the public URL for that. Do you understand the difference between the public URL (that the server gets a request for) and the directory that the middleware looks in for a matching file?
– jfriend00
Nov 10 at 0:54
1
@richie - Using the exact code in my answer, you would create a sub-directory under__dirname(where you app is located) and put the template files in there. But, you can obviously put them wherever you want and just pass the right path to them to therenderStatic()middleware so it knows where to look for matches.
– jfriend00
Nov 10 at 0:57
1
@richie - I modified my code so you don't need the.ejson the URLs.
– jfriend00
Nov 10 at 6:00
1
@richie - Notice that my latest version also has the security fix that prevents paths that walk UP the hierarchy with things like./in the path.
– jfriend00
Nov 10 at 6:22
1
@richie - By using an URL like this:/../../../app.js. This would be capable of looking on your hard disk ABOVE therenderPublicdirectory and fetching those files which is not what you want anyone to be able to do. That's why we disable it if there are any leading dots in any path segment.
– jfriend00
Nov 10 at 6:29
|
show 18 more comments
1
@richie - No. Don't addrenderPublicto the HTML page at all. That's local to the server only. That's where you PUT the template files on your server - not anything to do with the public URL for that. Do you understand the difference between the public URL (that the server gets a request for) and the directory that the middleware looks in for a matching file?
– jfriend00
Nov 10 at 0:54
1
@richie - Using the exact code in my answer, you would create a sub-directory under__dirname(where you app is located) and put the template files in there. But, you can obviously put them wherever you want and just pass the right path to them to therenderStatic()middleware so it knows where to look for matches.
– jfriend00
Nov 10 at 0:57
1
@richie - I modified my code so you don't need the.ejson the URLs.
– jfriend00
Nov 10 at 6:00
1
@richie - Notice that my latest version also has the security fix that prevents paths that walk UP the hierarchy with things like./in the path.
– jfriend00
Nov 10 at 6:22
1
@richie - By using an URL like this:/../../../app.js. This would be capable of looking on your hard disk ABOVE therenderPublicdirectory and fetching those files which is not what you want anyone to be able to do. That's why we disable it if there are any leading dots in any path segment.
– jfriend00
Nov 10 at 6:29
1
1
@richie - No. Don't add
renderPublic to the HTML page at all. That's local to the server only. That's where you PUT the template files on your server - not anything to do with the public URL for that. Do you understand the difference between the public URL (that the server gets a request for) and the directory that the middleware looks in for a matching file?– jfriend00
Nov 10 at 0:54
@richie - No. Don't add
renderPublic to the HTML page at all. That's local to the server only. That's where you PUT the template files on your server - not anything to do with the public URL for that. Do you understand the difference between the public URL (that the server gets a request for) and the directory that the middleware looks in for a matching file?– jfriend00
Nov 10 at 0:54
1
1
@richie - Using the exact code in my answer, you would create a sub-directory under
__dirname (where you app is located) and put the template files in there. But, you can obviously put them wherever you want and just pass the right path to them to the renderStatic() middleware so it knows where to look for matches.– jfriend00
Nov 10 at 0:57
@richie - Using the exact code in my answer, you would create a sub-directory under
__dirname (where you app is located) and put the template files in there. But, you can obviously put them wherever you want and just pass the right path to them to the renderStatic() middleware so it knows where to look for matches.– jfriend00
Nov 10 at 0:57
1
1
@richie - I modified my code so you don't need the
.ejs on the URLs.– jfriend00
Nov 10 at 6:00
@richie - I modified my code so you don't need the
.ejs on the URLs.– jfriend00
Nov 10 at 6:00
1
1
@richie - Notice that my latest version also has the security fix that prevents paths that walk UP the hierarchy with things like
./ in the path.– jfriend00
Nov 10 at 6:22
@richie - Notice that my latest version also has the security fix that prevents paths that walk UP the hierarchy with things like
./ in the path.– jfriend00
Nov 10 at 6:22
1
1
@richie - By using an URL like this:
/../../../app.js. This would be capable of looking on your hard disk ABOVE the renderPublic directory and fetching those files which is not what you want anyone to be able to do. That's why we disable it if there are any leading dots in any path segment.– jfriend00
Nov 10 at 6:29
@richie - By using an URL like this:
/../../../app.js. This would be capable of looking on your hard disk ABOVE the renderPublic directory and fetching those files which is not what you want anyone to be able to do. That's why we disable it if there are any leading dots in any path segment.– jfriend00
Nov 10 at 6:29
|
show 18 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233806%2fmiddleware-on-res-render-when-using-a-lot-of-routes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In this directory hierarchy, where is
__dirname? And, when you have a link like/javascriptin your side-menu, what file are you hoping for that to display? And, where is it?– jfriend00
Nov 10 at 1:52
I thought
__dirnamewas the "richie" folder since it's the root of all files & folders./javascriptis the name of the page -- I save info about the language on it.– richie
Nov 10 at 1:57
all these files (programming, c, cpp, python, javascript, php) are inside the programmingPublic folder
– richie
Nov 10 at 1:58
Are you trying to render files that have no file extension?
– jfriend00
Nov 10 at 2:01
they are all
.ejsfiles. I useapp.set("view engine", "ejs");on the app.js file (like I showed above) and it always works.– richie
Nov 10 at 2:04