sinatra files in public folder being routed? - ruby

I have public folder in root of my project. Placed a couple of images, when I try to access them, it says "Sinatra doesn't know this ditty..."
Isn't default public folder supposed to be called "public"? Or do I have to explicitly set that?

Need to not include /public in path.

The folder name should be "public" and then access it with /image.png when your folder structure is public/image.png

Related

Can you override mappings in wiremock

is it possible to have a base folder of mappings and then load other folders and if they have the same file names those latter folders override the mapping in the base folder
my set up would be like
#AutoConfigureWireMock(port = 0, stubs = {"classpath:/wiremock/base-mappings","classpath:/wiremock/spec-mappings"})
So if base mapping folder had a file serviceAresp.json
And the my specific folder also had a file serviceAresp.json.. which file would be loaded? or would they be merged?
Yes you can.
the last folder in the stubs part of the annotation will overwrite any files with the same name. (from what i have now tested with)

Security for downloading .bin files

I have created .bin file download functionality. All my .bin files are stored in the 'storage/app/files' folder. User from view template press on the download button, which appeals to the controller who handles all download functionality (checking if the user is logged in, are file is existing on 'storage/app/files' folder). My question is, does it's safe to store all my important files to this folder? Do I need to write a .htaccess file?
Only your public folder (with index.php) should be accessible, this is the root directory (sometimes the directory is named public_html).
Any directories outside that (like storage/app/vendor etc.) should be unreachable by URL.
"Everything" must go through index.php first if you want to keep control of your files.
So in order to serve assets like storage/app/files/xxx.png you should be using a controller. That code could look something like this:
// SomeController.php
public function showAvatar(Request $request)
{
// Select the `local` disk as defined in `config/filesystems.php`.
$disk = Storage::disk('local');
return response()->file($disk->path('files/xxx.png'));
}
You can then use middleware or other code to provide restrictions to these files.

OWIN WEB API self host resolve path to folder

Form inside an ApiController. I need to read content of a file embedded inside the project. But I can't resolve the correct path
[HttpPost]
public HttpResponseMessage DoSomething()
{
String content = System.IO.File.ReadAllText(#"~\SomeFolder\file.txt");
}
Doing like this the resolved path point to:
C:...\bin\Debug\~\SomeFolder\file.txt
instead of
C:...\SomeFolder\file.txt
Does anyone have any idea how to solve this under OWIN Self Host?
In general, it does not make sense to try to access a file inside a project. All the files necessary for deployment (dlls, assets, txts,...) should be copied to a separated folder so that when we need to deploy, we just need to copy that folder.
You should set the file as Copy To Output and try:
String content = System.IO.File.ReadAllText(#"SomeFolder\file.txt");
which is resolved to
C:...\bin\Debug\SomeFolder\file.txt
To make the code work with OWIN, you could take a look at this answer How do you resolve a virtual path to a file under an OWIN host?. It suggests using HostingEnvironment.MapPath and falling back to manipulating file paths manually in self host scenario.

Class 'MY_Controller' not found after download from webserver

Might be somehow copy of this thread but the choosen answer is not giving me a resolution.
I have copied site built on codeigniter to localhost from server and I get this error message. I have checked the case (altough Windows is non-case-sensitive) in the files and I am using MY_Controller as classname, filename and including file as well, made screenshots, see images:
1. Extending MY_Controller
File structure
MY_Controller class header
The file is in the core folder, but I still get this error message.
What am I doing wrong and what could be the solution?
In the index.php file in the root folder of the site check that the $system_path and $application_folder variables are correct. For example, I keep mine outside of the publicly accessible path, at the same folder depth as my public_html and so these for me are set as:
$system_path = '../system';
$application_folder = '../application';
If you've copied it from a web server then it's possible that something similar has been setup or perhaps an absolute path has been specified.

Codeigniter controller in subfolder extends outside one

Is it possible a controller inside a subfolder, lets call it 'category', extends from a controller from the parent folder?
Example:
application_controller.php in the controller folder
category in the folder controller/category
It keeps me showing the error
require_once(../application_controller.php) [function.require-once]: failed to open stream: No such file or directory
Is there some trick i'm missing to do that?
Thanks in advance
Elkas
You're technically executing in a wierd scope because of how the controllers are loaded up.
require_once(APPPATH.'controllers/application_controller.php');
This is what you're looking for.
APPPATH will always point to your application/ folder.

Resources