I'm facing this problem while entering a wrong URL in the browser. It supposed to take me to the 404 notfound! page.
BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
at new BSONTypeError (/mnt/d/Programming Hero/Assignment-11/fragrance-warehouse-server2/warehouse-management-server-side-shamimulhaque1992/node_modules/bson/lib/error.js:41:28)
404 page route.
<Route
path="*" element={<Notfound></Notfound>}
>
</Route>
The route where put wrong value, for testing purpose.
<Route
path="/updateitem/:updateId"
element={
<RequireAuth>
<UpdateItem></UpdateItem>
</RequireAuth>
}
></Route>
Client side URL
const url = `http://localhost:5000/updateitem/${updateId}
Related
I am trying to get URL which I am getting after redirection if do following:
cy.url().then(url => {
cy.log(url);
});
Then I get logged initial URL, but not the (new url), how do I get url in cypress after redirection?
redirection img (new url)
Solution:
To get the redirected URL just simply add cy.get and your element so it will wait until the redirect page loads. Here is the working solution for me:
cy.get('.crumb > p')
cy.url().then(url => {
cy.log(url);
});
Exactly as you wrote, you need to first wait for a element from the new URL to be visible, using a cy.get('any-element-from-the-new-url').
After that you can get the new URL just using cy.url(), in this case if you want to log this URL you can just use cy.log(cy.url()).
A more meaningful approach would be to add an assertion on the pathname to what you are expecting. The docs can shed some light on the cy.location(). You can use an include assertion on the pathname in the situation that you will not know all of the url string.
// visiting url - https://website.com/favorites
// redirects to - https://website.com/favorites/regional/local
cy.location('pathname') // yields "/favorites/regional/local"
.should('include', '/favorites/')
.then(cy.log)
If you do this, you don't have to do any previous step. Especially because the expectedUrl doesn't have to match the actual url which allow your test doesn't crash if that happens.
cy.url('match', 'expectedUrl').then(el=>{
cy.log(el)
})
I'm using express to interact with discord's oauth2 api.
When I request a user oauth token the server responds with a url like:
http://localhost:3000/index#token_type=Bearer&access_token=tkn&expires_in=int
I'm trying to extract the parameters after the # as with discords api parameters start with # unlike others which start with a ?
Because it doesn't start with a question mark I am unable to use the req.params.x property.
I thought, "No big deal, ill just get the url and extract it myself" but every single url accessor in express removes string after #. This includes req.url and req.originalUrl which both return the file path.
So how can I get url parameters started by hashtags instead of question marks?
Or How can I get the full url with content after hashtags
I was able to solve this problem by setting a custom query parser. Code snippet below.
const app = express();
app.set('query parser', (query) => {
return query.split('&').map(item => {
const [key, value] = item.split('=');
return {
key,
value
}
});
});
app.get('/', (req, res) => {
console.log(req.originalUrl); // Full URL starting with file path
})
I am using a url rewriting functionality in my application(SparatcusV3.4).
I am calling my backend from node js to check a productcode exists or not
for that I need the current browser url entered by user in the address bar.
I am accessing the url using below code
const fullUrl = req.protocol + '://' + req.get('host')
this is working fine on my local system but when deployed on any environment(by SAP)
this URL is coming as "127.0.0.1:4200" , what might be the problem here with environment ?
or what is the correct way to get the full browser url entered by the user ?
any help would be appreciated!!!
thanks in advance
Please refer to this part of Spartacus docs: https://sap.github.io/spartacus-docs/server-side-rendering-coding-guidelines/#getting-the-request-url-and-origin
It suggests to use SERVER_REQUEST_URL and SERVER_REQUEST_ORIGIN injection tokens when using the setup that's running SSR behind a proxy in order to resolve URLs.
To use these optional tokens:
it is assumed you're using Spartacus' NgExpressEngineDecorator from #spartacus/setup/ssr in your server.ts file.
when injecting them, you should mark them as #Optional (per docs), as these are not available in CSR application.
const obj = {};
const rc = request.headers.cookie;
rc?.split(';')?.forEach((cookie: any) => {
const parts = cookie?.split('=');
obj[parts.shift().trim()] = decodeURI(parts?.join('='));
});
return obj;
it can give list of all cookies in request object so with OBJ['RT'] can give the value and further splitting with '=' we cna get the exact request URL there from we can extract the host and the origin uding below code
const cookieName = 'RT';
const cookieObj = this.getCookieasObject(req);
let fullURL = cookieObj[cookieName];
if (fullURL) {
fullURL = decodeURIComponent(JSON.parse(fullURL).split('=')[1]);
}
const url = new URL(fullURL);
const baseUrl = `${url.protocol}//${url.hostname}`;
The router mode is "history", and I want to valid each request in the middleware which will redirect the request to a given page when the request is invalid. In my case, the request that does not exist in the white_path will be redirect to '/500':
export default function (context) {
const white_path = new Array('/login', '/404', '/500')
const cur_path = context.route.path
if(white_path.indexOf(cur_path) < 0){
context.redirect(301, '/500')
}
}
But the problem is that when I input the url: http://localhost:3000/blog/SampleTitle/#first-paragraph, but then it redirects to http://localhost:3000/500#first-paragraph. Why the hash value does not disappear? In the middleware, the hash value is empty, but after redirect to the client, the hash value becomes the one appear in the last url.
How can I solve it? Thank your very much!
I just moved my nolayout.aspx to 404 error page inside config file, everything is working fine except the URL. After getting redirect to 404 URL has these extra information :
404?item=%2fservices-and-solutions%2fbusiness-vision%2fit-without-boundaries&layout={00000000-0000-0000-0000-000000000000}&device=Default
I dont want URL having this : &layout={00000000-0000-0000-0000-000000000000}&device=Default
Config settings is :
Rest is fine for me, kindly suggest.
That URL is generated from sitecore. It's not IIS. This one you are getting is when the item doesn't have a layout set. You might also want to look at the not found url. You can set these urls to point to sitecore items in web.config:
Unfortunately, sitecore does not return a Not found status code, so it is better to create your own handler to read the Item and set the status code. See an example here from RUUD VAN FALIER: http://www.partechit.nl/en/blog/2012/11/return-404-status-code-when-itemnotfound-page-is-loaded
Basically, you append a processor after Sitecore.Pipelines.HttpRequest.ExecuteRequest and override RedirectOnItemNotFound and the RedirectOnLayoutNotFound as necessary.
I think you just need to add an additional section to <system.webServer> in your web.config.
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404" responseMode="ExecuteURL" />
</httpErrors>
As well as setting RequestErrors.UseServerSideRedirect to true.
Reference: http://herskind.co.uk/blog/2012/03/sitecore-404-without-302
Also you can add existingResponse="PassThrough" along with erroMode
Check detailed explanantion at: IIS httpErrors
Thanks guys, Surely I am going to try all the suggestion given above and will see which one is working finest with this case.
Right now I just implemented a code in my redirect module with every time of querystring appending on sitecore URL's
`Defined a baseURL using Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item);
if (baseUrl.ToLower().Contains("?"))
{
ReqUrl = baseUrl;
baseUrl = ReqUrl.Substring(0, ReqUrl.IndexOf("?"));
AppendedUrl = ReqUrl.Substring(baseUrl.Length);
}
string Qurl = Request.RawUrl;
if (Qurl.ToLower().Contains("?"))
{
Qurl = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
AppendedUrl = Request.RawUrl.Substring(Qurl.Length);
}
if (Qurl.ToLower().EndsWith("/"))
{
baseUrl = baseUrl + "/";
}
//Code for URLEncoding
string fullPath = baseUrl + AppendedUrl;
fullPath = System.Web.HttpUtility.UrlDecode(fullPath);
if (fullPath.ToLower().Contains("&layout"))
{
fullPath = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("&layout"));
}
if (baseUrl.ToLower() != Qurl.ToLower())
{
Response.RedirectPermanent(fullPath);
}
}
}`
so URL encoding and putting condition with types of querystring exist in website resolved my problem.
Thanks again for ideas, I am going to see alternate ways too from them.