Making a route exception for a static file - angular2-routing

I've got some software out in the wild that needs to download some static file from a specific place on my domain: domain.net/somefolder/setup.exe. While I plan to change this, it's going to take a long time due to constraints out of my control.
In the meantime, how can I deal with this in my Angular2 router? Essentially, if Angular sees this specific url it should not try to resolve the url and instead serve the static file similar to how it would behave if you accessed static files from the assets folder.
{ path: 'somefolder/setup.exe', ... }

I ended up just doing a url rewrite on the web server level within a config.

Related

Next.js production mode public folder can't access dynamically [duplicate]

I have a project in Next.js. I have that upload files and share that in public URL to this project.
With npm run dev first I uploaded files to public folder and it worked fine, but when I change to npm run start and upload files, the files upload to public folder but with URL http://mydomain/fileuploaded.jpg it did not show, is rare but it's there.
I searched on the Internet but I didn't find a solution for this problem.
From Next.js documentation:
Only assets that are in the public directory at build time will be served by Next.js. Files added at runtime won't be available.
You'll have to persist the uploaded files somewhere else if you want to have access to them in the app at run time.
Alternatively, you could setup your own custom server in Next.js, which would give you more control to serve static files/assets.
You can also achieve something similar using API routes instead. See Next.js serving static files that are not included in the build or source code for details.
a bit late but if someone need the same.
If your goal is to upload and get picture from your next server, you can instead of using the Next router, getting the image by yourself by create a route /api/images/[id] where [id] is your file name and you manually with fs send the picture back.
something like:
const file = await fs.readFile(`./uploads/image.png`)
console.log(file)
res.setHeader('Content-Type', 'image/png')
res.send(file)
Try and use nginx or another webserver to serve the public directory. That way it will serve newly added files without having to write extra code to serve files in nextjs.
server {
/images/ {
root /var/www/site/public
}
}

Can I serve static content with spring-boot-starter-tomcat but without spring-boot-starter-web?

I'm working on a web service using spring-boot-starter-jersey and spring-boot-starter-tomcat (v. 1.5.2) and as such, I'd rather not add spring-boot-starter-web and further complicate my configuration. I want to stick the Swagger UI static files in a folder and serve them from there.
What I'm wondering is, can I serve static files using just spring-boot-starter-tomcat? I've found Spring documentation saying that I can server static content from a variety of sources on the classpath, but the examples I've found seem to require Spring MVC. I've tried disabling Jersey and putting static files in src/main/resources/static to test just Tomcat, but when I go to localhost/index.html, I get a 404 not found error.
As you might be able to tell from my path, I'm using Maven.
Since you can serve static files with just Tomcat, it seems like I should be able to serve static files with spring-boot-starter-tomcat. If this is the case, where do I put those files?
To put this another way, say I have started with the Spring-provided
spring-boot-sample-jersey project. I have a requirement that the Jersey web service answer calls to the root address (/). How would I add some static content (HTML, CSS, JS) to be served from subdirectory called /swagger?
So the default servlet (which serves static content) is by default registered. But it will use only search specific paths as the document root. I had to go digging through source code to finally find it. If you look in the AbstractEmbeddedServletContainerFactory, you'll see
private static final String[] COMMON_DOC_ROOTS = {
"src/main/webapp", "public", "static" };
If we don't explicitly set the document root, the above three are the paths that will be searched. In order, the first directory found that exists, will be used as the document root. I've verified that all of these work.
If you want to set a different directory, you can use a customizer bean
#Bean
public EmbeddedServletContainerCustomizer tomcatCustomizer() {
return new EmbeddedServletContainerCustomizer() {
#Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setDocumentRoot(new File("src/main/resources/static"));
}
};
}
The one thing I haven't figured out is if we can serve files as classpath resources, instead of file system resources. If you look at the source code I linked to, it has some code that looks for the existence of a META-INF/resources. I thought that might work, but unfortunately it didn't for me. Maybe some guys of the Spring Boot team can enlighten us.

spring Resource handler not handling /../**

I'm using spring boot with thymeleaf and all my resources are outside spring application on a path like "/../../css/main.css". On dev env should resolve the path using an url and live env go on the path.
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String templates=env.getProperty("spring.thymeleaf.prefix");
registry.addResourceHandler("/../../css/**")
.addResourceLocations(templates);
}
// spring.thymeleaf.prefix = http://website.com/assets/
Why the resource handler is not handling these kind of resources, but if I "/**" is handling without problems? Am I missing something?
Edit: if resourceHandler is "/css/**" and location is an url is not being handled either
You can't reference to external resources as you want cause resolver looking for resources from classpath.
Try to do it like in this issue - Add external resources folder to Spring Boot or in this - How do I use Spring Boot to serve static content located in Dropbox folder?
I am pretty sure that using .. in the addResourceHandler is not valid but I do not have specific documentation to back it up. The path is describing a pattern that the server gets not what is listed in the browser. From the function doc: "based on the specified URL path patterns". If you reference .. from a browser that will still be changed to some absolute path to be sent to the server. This is why your other versions work without issue.

Retrieve embedded static resources (css/img/etc) using Virtual Path Provider instead of GetWebResourceUrl

I have an asp.net 4.0 webforms website with a CSS stylesheet which I've embedded into a separate assembly.
If I load the css using ClientScript.GetWebResourceUrl it loads, but does it with that /WebResource.axd?whateverlongstringofstuff
I was hoping that I could use a Virtual Path provider so that i can simply reference it by linking to say ~/Custom/my.css
where ~/Custom/* would go through the VPP and serve it from the embedded resource.
the reason I was doing this is I want users to be able to easily override my css by adding the actual css file in that location so it serves that one instead.
However, no matter what I try, I get a 404 on that resource url, even though in my custom ResourceResolver, the fileExists resolves to true (because it does find it in the resources assembly).
So I suspect this is because IIS is configured to serve static files (css, jpg, png, etc) directly, bypassing anything I could add to the pipeline, and the only way around this would be to have my users change their web.config or IIS settings.
Is this true? because if it is I'll abandon this and go back to the WebResource.axd, but it would really be nice if this could be done

Get Static referenced files with http request in meteor

This can be a silly question but I have had some issues with it. I am trying to implement jwplayer with meteor. Jwplayer will try to get a file based off the url you suggest. So I tried to place a file in localhost:3000/test.mp3. When I tried to hit that url I get just the default site. This would work if I used tomcat. Is there something I can do to get the files relative to meteor directory?
Thanks for your help.
In the /public directory, per the docs:
Lastly, the Meteor server will serve any files under the public directory, just like in a Rails or Django project. This is the place for images, favicon.ico, robots.txt, and anything else.
Meteor hasn't yet implemented server side routing and all directories are ultimately flattened. So for the time being, you can access your file at http://localhost:3000/test.mp3, but that may change in the future.

Resources