prentend that I have a file in .../web/main.dart and when I'm serving the app ( webdev serve web:8080) it will be located in localhost:8080/main.dart.js and the packages in localhost:8080/packages/ is there anyway to move them to localhost:8080/foo/main.dart and localhost/foo/packages/ ?
Basically add /foo/ to all dartdevc generated dictories.
No, that is not supported by the default dev server (and is unlikely ever to be).
The typical way to do this would be to set up a separate server, which delegates all things under the /foo route to the dev server, and strips out /foo from the path.
Related
I have been handed a Ruby Project that creates a document and serves it to the user, when I try to access the file on a local environment it it is delivered correctly, (this is the code that does so).
filepath = Rails.root.join("public",#records.document.url)
send_file (filepath)
So I know the file is constructed correctly and sending it to the user using send_file works at least in a local environment.
But when it's deployed on the production server (running Amazon EC2, ubuntu, deployed with dokku) I get a 500 Internal server error:
ActionController::MissingFile (Cannot read file *path of the file*)
Few things I'm noticing: doing a find / -iname "*filename*" tells me the file is stored in var/lib/docker/overlay2/*container_name*/merged/app/public/filename and var/lib/docker/overlay2/*container_name*/diff/app/public/filename but the result of joining Rails.root with the filename is app/public/filename, do I need to pass send_file the whole filepath?
I googled for a couple hours and it seems nginx has no access to the public folder because it's running in the host machine while the app is inside a container? How would I know if that is the case and if so, how should I serve the file?
The person who originally wrote the code told me to use OpenURI.open_uri() but googling it doesn't seem to turn up anything applicable to the situation.
Nothing you're doing here actually makes sense - its sounds like you're just following a bunch of misinformation down a bunch of rabbit holes.
The way this is supposed to work is that the files in /public - not /app/public are served directly by the HTTP server (NGinX or Apache) in production and your Rails application in development (so you don't have to configure a local HTTP server). The /app directory is for your application code and uncompiled assets. Do not serve files from there - ever.
The /public directory is used for your compiled assets and stuff like robots.txt, the default error pages and various icons. Serving the files directly by your HTTP server is far more efficient then serving them through your Rails application. You can do a litmus test to see if serving static assets are working by sending curl -v YOUR_URL/robots.txt.
If this isn't working in production you need to check your NGinX configuration. There is no shortage of guides on how to serve static files with NGinX and Docker.
Serving files with a Rails controller and send_data / send_file should only be done when its actually needed:
The file is not a static file or something that can be compiled at deploy time.
You need to provide access control to the files with your application.
Your proxying files from another source.
I'm developing a web project with Google Dart SDK version 2.2 and using PhpStorm as my IDE. The project is intended to start with a index.php file which does some preliminary server side work at the end of which is a call to include('project1.html'); which downloads the html file to the client and includes <script defer src="project1.dart.js"></script> at the end. I'm trying to figure out the best setup for development. I have php installed on the development machine and included in the path.
I have found that calling webdev serve from the terminal serves the project to http://localhost:8080 but displays Could not find web/index.html instead of the expected rendering of project1.html. So I guess the webdev server does not handle .php files?
Another approach is to right click the index.php file and select run in browser. This brings up a Chrome page displaying the text of the index.php file. So again php not processed I guess.
Another approach is to set up a javascript debug configuration with default settings and clicking the green debug icon. This does produces the correct project1.index output and the index.php has been correctly processed. However, I cannot get breakpoints to work and errors in the Chrome Dev Console refer to the project1.dart.js file in the build directory.
Another approach I tried is using an Xampp server to serve the files. In this case I had a number of projects and set each up under xampp/htdocs i.e. xampp/htdcos/project1 etc. In PhpStorm I set up a local or mounted server with:
folder C:\xampp\htdocs\project1,
webserver root url http://localhost/project1,
local path pointing to the web subdirectory of my project, and
deployment and webpaths both set to \.
PhpStorm seems to work ok but again breakpoints did not work and debug error messages did not refer to the dart files.
Any help would be most welcome. Is what I am trying to do even possible with this setup i.e. starting with an index.php file?
** EDIT **
Following advice below, I added following to my httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/project1"
ServerName localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPassMatch ^/(.*\.js)$ http://localhost:8080/$1
</VirtualHost>
Then I keep my .php files and MySql on Xampp and javascript is served by webdev serve.
However, I have the same problem i.e. breakpoints in PhpStorm or Chrome dev tools source Dart files don't trigger and Chrome dev tools console refers to javascript files instead of Dart source.
You need to run a reverse proxy on the apache/php server and redirect js requests to webdev server, then you just run your application testing using the apache/php server and any browser. When you go to deploy, use dart2js to generate the js files and copy the whole build directory where it can be read by a normal apache/php server (i.e. no reverse proxy).
So we have resources in the grails-app/assets folder, i.e: javascript files, stylesheets and other documents.
Some of these documents are user docs which would have to have the option of being updated in production mode. When you usually add something to this assets folder, the grails app doesn't detect this change until after redeploying the app which would cause the folder to be reprocessed.
Is there any way to detect these changes in production systems or an alternate location other than the assets folder where grails would pick up this new/updated file without re-deployment ?
Under production the most recommendable approach is to have an Apache Httpd or an NGinx server as a front end where you put the static assets. In both cases you will need configure reverse proxy on NGinx or mod_jk (depending of your Java container.).
Inclusive you may think on store large assets in a repository like S3 (if you will run on Internet).
I am trying to configure Rails production server with Apache 2.2, Passenger 4.0.59 and XSendFile 0.12. Application is deployed via Capistrano.
Deployed application produces (maybe large) PDF to #{Rails.root}/tmp and serves this file using send_file.
The problem is that Capistrano uses symlinks to point to currently deployed version of application. XSendFile on the other hand dereferences symlinks and refuses to serve a file if its real location is outside document root even if it is allowed by XSendFilePath. Apache's error.log states:
(20023)The given path was above the root path: xsendfile: unable to find file: /resolved/path/to/file.pdf
Everything works well when I set PassengerAppRoot and XSendFilePath to the real location of current version of application, without symlinks on the path. But it's OK until next deploy, which requires apache reconfiguration. Not very useful.
How should I configure Capistrano deploy and XSendFile parameters to make it work together?
I tried solutions with ln -nFs described in Capistrano & X-Sendfile and in mod_xsendfile with symbolic links but none works.
I finally managed to make it work. A few tips for the ones who will have problems with XSendFile
I set XSendFilePath to user's $HOME, there are no symlinks on the path to $HOME, so it works. I can accept this from functional and security point of view, but it is obviously a workaround.
Be aware that XSendFilePath is sensitive to paths containing multiple slashes /like//this. I am using apache macros and while concatenatingXSendFilePath parameter from a few macro parameters I put some obsolete slashes. This caused XSendFile to refuse to send files.
Good luck!
Hello I dont know what is the best way to redirect all on public. I'm doing on server, not on local.
On local I can make VHost and editd host file but when i put with FTP on server www.example.com I cant make vhost.
How now can do redirection on public ?
On www.example.com he list me directory structure :
config/
data/
init_autoloader.php
module/
public/
vendor/
I really don't know apache .htaccess any example how to do that redirection.
Thanks.
You don’t need to do it yourself. It’s done by your web hosting provider. It can point to the public_html folder instead of public but that doesn’t matter. So you can just add your other folders as siblings to the public_html and it’s done.
The redirection part is taken care by the .htaccess files put under the root folder of host, below is my answer to one of this similar question, the link that shows how to host a ZF2 app in a shared hosting environment
zf2 installation on shared hosting server