Can [parameters] be inserted dynamically into paths in Next.js? - next.js

I'm running into a problem trying to get routes working with [params]/:params.
The paths I'm working with will always be structured as follows:
console/sites/[siteId]/possibly-another-directory/page.
The console/sites portion I can set as basePath in next.config.js but the [siteId] is something I would rather not have to manually add to every path in order to not end up with console/sites/possibly-another-directory/page. Is there a single place I can set this so that it will be included in every path I link to from within my site?
FWIW, I've tried setting my basePath to /console/sites/:siteId but :siteId was being read as a literal value.

Related

"./src/**/*.{html,js}" in tailwindcss's content what does this asterisks mean?

Are this "*" mean anything like "." or ".." when we define path? I am not getting what those means. Why can't I specify the path in the usual way? I wanted to use paths like "../../XYZ" or something like that. But where is this asterisk coming from and what does it mean? Can I define the path in tailwind without using the asterisk?
If anyone can help I would be most glad. I am new to tailwind CSS so a little bit confused. Thank you.
The asteriks are used for dynamic imports for if you want Tailwinds to scan for content in any folder that is under ./src/ (asuming you are using ./src/**/*.{html,js} as content in tailwinds.config.js file. That means if you use ./src/**/*.{html,js}, the first two ** will look for any folder inside ./src, including subfolders.
So, for example, file path in your configuration file will most likely look like:
./src/**/*.{html,js}
./something-else/**/*.{html,js}
And these configured paths will "translate" to something like:
./src/folder1/file.html
./src/folder1/file.js
./src/folder1/subfolder/file.js
./something-else/folder1/file.html
./something-else/folder1/file.js
etc..
Which means if you add a file with the .js or .html extension in the specified folder(s), Tailwinds will automatically include these files in your project.
According to the documentation, you don't want to use really broad path configurations like /**/*.{html,js}' but rather use something like:
./components/**/*.{html,js}
See the Tailwinds content configuration documentation for more examples.
you can use * to match anything except slashes and hidden files,
and use ** to match zero or more directories.
check this site it will help you:
https://tailwindcss.com/docs/content-configuration

How to create MPEG-DASH manifest with multiple fallback URL?

I have a URL like this http://.../test/index.mpd. What I want is create another dash manifest that will contain multiple fallback URLs pointing the original manifest file.
For example for URL http://example.com/test/index.mpd (original manifest), the new manifest file should contain multiple CDN URLs like:
http://cdn1.com/example/test/index.mpd
http://cdn2.com/example/test/index.mpd
http://cdn3.com/example/test/index.mpd
I found something similar in following URL https://bitmovin.com/docs/player/faqs/how-can-i-utilize-the-cdn-fallback-feature-of-the-player. However, this example adds base URLs to the original manifest file and It does not work for dynamic manifest(live stream). Is there any way to do that. I cannot find good documentation or examples on dash manifest manipulation.
The proper way to do this is via BaseURLs. What do you mean by "It does not work for dynamic manifest"? BaseURLs work independently of the manifest type and definitely do work in dynamic manifests. Perhaps your player is at fault?
Another option is to specify the alternative MPD URLs in <Location> tags which allows you to specify multiple locations at which the MPD is available, but IMO BaseURL is better specified for CDN failover.

Omnifaces FileServlet - change Output link path from image

I´m using the FileServlet from Omnifaces:
http://showcase.omnifaces.org/servlets/FileServlet
It works fine and all my images appears in my webapp.
But now I would like to change the link from the image because I would like to avoid that someone enter the path from another image:
For example:
The path from one image is:
myapp/imagesservlet/mypic1.jpg
-> Someone can enter
myapp/imagesservlet/mypic2.jpg -> and got another image.
My files are stored as:
mypic like mypic1.jpg, mypic2.jpg.....
Is there any chance to change the path and got also the correct image?
Just use unpredictable autogenerated filenames. E.g. imgur also does that. This responsibility is actually beyond the OmniFaces FileServlet as all it does is just inspecting the passed-in filename and serving it up. You should change the passed-in filename to be an autogenerated one. Save if necessary the original filename somewhere else, e.g. in a SQL database, if necessary along with other metadata (content type, size, etc) so it can more efficiently be indexed and searched.
How to autogenerate a random string in Java is already covered in this Q&A: How to generate a random alpha-numeric string?

How can I change this .NET code to File.Exists?

I am working with a framework written in .NET and I do not know .NET. I just need to change this one line where it checks to see if a variable exists, and I need to change it to instead just check on the server to see if the file itself exists.
Here is what is there now:
#if (!string.IsNullOrEmpty(Model.DrawingLink2){
Is this the correct code to change it to check if the file exists instead?
#if (File.Exists(/Portfolio/#(Model.FileNumber)/Images/Large_#(Model.FileNumber)_1.jpg))
You need to map that file, relative to the root of the web application, to the physical file system. You can use HttpServerUtility.MapPath for that. You also need quotes around string literals. The process running the code also needs read access to the directory (very likely the case, just mentioning it to be complete).
#if (File.Exists(HttpServerUtility.MapPath("/Portfolio/#(Model.FileNumber)/Images/Large_#(Model.FileNumber)_1.jpg"))

Relative path for a included file - ASP/HTML

Sorry if this question is answered somewhere else but I tried searching several pages and was unsuccessful.
So i have an include file (sidebar) which i am using in all pages.
Default.asp
Products.asp
Salary/Survey.asp
inc/sidebar.asp (this is the included file)
now inside sidebar.asp I have a link for Salary/Survey.asp
from all other pages at root level, i can simply use href='Salary/Survey.asp' and will work fine. but when I am on page Survey.asp , writing href='Salary/Survey.asp' will become actually Salary/Salary/Survey.asp. I understand it has to be ../Salary/Survey.asp to be used properly but it will then not work for root level pages.
I can not use root relative which is /Default.asp and /Salary/Survey.asp as I am working for someone else' project and i dont know his directory structure and thus i only have option to document relative path.
Hope this is clear to understand and someone helps me out.
Thanks!
We solved this problem the following way...
Each of our asp pages included a special file that Dims and sets golbal variables. We called ours Info.asp
Inside Info.asp we defined a variable called strRelativePath
Dim strRelativePath
strRelativePath = ""
Every asp page set the relative path according to it relative position:
for example:
Root pages - strRelativePath = ""
One level deep pages - strRelativePath = "../"
Two levels deep pages - strRelativePath = "../../"
Then it was a matter of prefacing all the links requiring a relative path with <%=strRelativePath%>
you need to get write this after the that - Salary/Survey.asp
You can get the virtual path to the file from one of several server variables - try either:
Request.ServerVariables("PATH_INFO")
Request.ServerVariables("SCRIPT_NAME")
Either server variable will give you the virtual path including any sub-directories and the file name - given your example, you'll get /virtual_directory/subdirectory/file.asp. If you just want the virtual directory, you'll need to strip off everything after the second forward slash using whatever method you prefer for plucking a directory out of a path, such as:
s = Request.ServerVariables("SCRIPT_NAME")
i = InStr(2, s, "/")
If i > 0 Then
s = Left(s, i - 1)
End If
or:
s = "/" & Split(Request.ServerVariables("SCRIPT_NAME"), "/")(1)
basically, if your sidebar can be included from programs in different folders, the only 'easy' way is to use absolute paths like you mentioned.
You say can't use it, so I would think of different ways...
virtual folders: In IIS you could set a virtual folder in salary folder for 'salary' and point it to the site's root.
OS links (similar to above, but at the OS level)
use mappath. You could check mappath to see the actual folder you're in, and use the correct include (with/without /salary) though I'm thinking this might give you an error, not sure.

Resources