In my xpages app I want to redirect the user based upon a role. However the computed URL results in a ugly URL with %5C in the pathname
var baseURL = context.getUrl().toString().split(facesContext.getExternalContext().getRequest().getRequestURI())[0];
var path =escape(database.getFilePath());
if (context.getUser().getRoles().contains("[Administrator]") || context.getUser().getRoles().contains("[SuperAdmin]") || context.getUser().getRoles().contains("[Ledamot]")){
facesContext.getExternalContext().redirect(baseURL + slash + path + "/employees.xsp?sorting=asc")
}else{
context.redirectToPage("index.xsp")
}
This results in something like: : https://server/directory%5cdatabase.nsf/employees.xsp?sorting=asc
Since you are redirecting to the same database, you can calculate the url prefix (host + database path) like this:
context.getUrl().toString().split(view.getPageName())[0]
%5c is a backslash, so what you have to do is replace backslashes in the filepath with forward slashes. So something like this should work:
database.getFilePath().replace("\\", "/");
Related
I have a Node JS app that has a URL like this:
/app/:vehicleNumber/details
It takes vehicle numbers dynamically in URL.
The prom-client based metrics API for HTTP calls is returning all the URLs as separate URLs instead of clubbing them as a single URL with vehicleNumber as a variable.
http_request_duration_seconds_bucket{le="0.003",status_code="200",method="GET",path="/app/GJ98T0006/details"}
http_request_duration_seconds_bucket{le="0.003",status_code="200",method="GET",path="/app/KA28T6511/details"}
.....
I want the count based on a single URL.
e.g.
http_request_duration_seconds_bucket{le="0.003",status_code="200",method="GET",path="/app/{var}/details"}
It is happening when a UUID is present in the URL but not for vehicle numbers present in the URL.
Assuming you're using Express, you likely want something like:
let path = null;
if (req.route && req.route.path) {
path = req.baseUrl + req.route.path;
} else if (req.baseUrl) {
path = req.baseUrl;
} else {
/*
* This request probably matched no routes. The
* cardinality of the set of URLs that will match no
* routes is infinite, so we'll just use a static value.
*/
path = '(no match)';
}
path will be /app/:vehicleNumber/details. The req.route part may not be necessary for your use case, but it doesn't hurt -- it comes in to play if you're using express.Router({ mergeParams: true }) to compose your routes.
I'm using serve-static, and it works perfectly with, for example, the string '/var/www/html'.
But, when I write
http.createServer(function(req, res){
var serve = serve-static(req.url, ...)
serve(...)}
with the url:
localhost/var/www/html
It returns me :
'can't get /var/www/html'
How can I redirect my request to the root of my serve-static site?
Ok, I just figured out, that, if I want to put the directory in my url,
I just need to set serve-static('/', ...)
and it will automatically add the url directory
you have to concat the root path, which is in the var __dirname
var serve = serve-static(__dirname + req.url, ...)
Sometimes i need create a absolute link in a web site.
Like http://example.com/xxxx/xxxx?foo=bar not /xxxx/xxxx?foo=bar
Here has anyway to create a simple helper for express manually?
Just like:
app.locals.url = function ( pathTo, opts ) {
// Somethings here.
}
I think they may need SSL check, host and route check or somethings.
You can create the full URL :
var URL = req.protocol + '://' + req.get('host') + req.originalUrl;
Them You can redirect to this URL
On Windows machine, I have a mapped share folder => Z:/uploads/
using express, I use res.senFile to return a file to the browser:
var download = config.file_dir + "/" + file;
res.sendFile(download);
download value is Z:/uploads/737237213791239.pdf
I get this error:
throw new TypeError('path must be absolute or specify root to res.sendFile
Am I giving a absolute path?
I hit the same issue. I found it easiest to configure my folder with forward slashes, the use path.join to send. This should work work a drive letter or UNC path.
var path = require("path");
config.file_dir = "z:/folder";
//use forward slashes for UNC if you wish to use that instead ie //server/share
var file = path.join(config.file_dir, urlPath);
res.sendFile(file, (err) => {
if (err) {
res.status(err.status || 500).send();
}
});
I'm using the following get:
app.get("/:project/*", auth, function (req, res) {
Then parsing against a config file to load a directory dynamically:
var path = req.params[0] ? req.params[0] : "index.html";
res.sendfile( path, { root: "./builds/" + config[req.params.project].dir + "/dist/" } );
Which works great, only problem is that it requires my urls to end with a "/" if I'm going to the default (index.html). For example, I have to use http://server.com/some_project/ and if the trailing slash isn't there it throws a Cannot GET /some_project error. Curious if there's a way around this?
app.get("/:project/?*", ...)
Add the question mark. That should allow you to do with or without the trailing slash.