1. euphoria-mvc - app:run()
- Posted by jmduro Jan 06, 2021
- 853 views
When I'm trying euphoria-mvc with the development server ( server:start() ), I enter a route in the browser to see it in action.
When using following example (index.esp) with an Apache server in CGI mode ( app:run() ), I don't know what to do:
- to run the script in CGI mode I must address the script ( http://localhost/index.esp ), but I get an error 404.
- to access a route, I would have to address the route ( http://localhost/ ) but there is no route since the script has not been run.
Did I miss something ?
include mvc/app.e include mvc/server.e include mvc/template.e include mvc/logger.e include std/map.e function index( object request ) object response = map:new() map:put( response, "title", "My First App" ) map:put( response, "message", "Hello, world!" ) return render_template( "index.html", response ) end function app:route( "/", "index" ) -- "/" is the URL path, "index" is the name of the route -- route() will find the matching routine automatically set_log_output({ "!debug.log" }) -- overwrite debug.log each time set_log_level( LOG_DEBUG ) --server:start("0.0.0.0", 8080) app:run()
Jean-Marc
2. Re: euphoria-mvc - app:run()
- Posted by ghaberek (admin) Jan 06, 2021
- 854 views
Did you follow the Add CGI Handler part of the README? Basically, the app:run() handler expects the web server to be doing path rewrites and using your script (index.esp) in CGI as the default path handler.
# Add CGI handler for index.esp AddHandler cgi-script .esp DirectoryIndex index.esp Options +ExecCGI # Send all non-existant paths to index.esp RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.esp/$1 [L,NS]
Edit: Also your script needs to be marked executable (chmod 755) and have the correct shebang (#!/usr/local/bin/eui) in the first line of the file.
-Greg
3. Re: euphoria-mvc - app:run()
- Posted by jmduro Jan 07, 2021
- 837 views
First error: my Apache configuration missed module rewrite. After I corrected this failure I still had an error page (HTTP 404).
The .htaccess file disables PHPMyAdmin which is needed on my LAMP server. I got the same 404 error as with the EU script. However a PHP script in the document Root works (phpinfo.php).
I removed the .htaccess file, I put your Add CGI Handler instructions in a file named /etc/apache2/conf-available/eui4.1.conf, I enabled the configuration with sudo a2enconf eui4.1 and I reloaded Apache configuration with sudo systemctl reload apache2.
PHPMyAdmin works again but the browser just shows the script source code instead of executing it.
#!/usr/local/bin/eui include mvc/app.e include mvc/server.e include mvc/template.e include mvc/logger.e include std/map.e function index( object request ) object response = map:new() map:put( response, "title", "My First App" ) map:put( response, "message", "Hello, world!" ) return render_template( "index.html", response ) end function app:route( "/", "index" ) -- "/" is the URL path, "index" is the name of the route -- route() will find the matching routine automatically set_log_output({ "!debug.log" }) -- overwrite debug.log each time set_log_level( LOG_DEBUG ) --server:start("0.0.0.0", 8080) app:run()
Here is my /var/www/html directory:
8:/var/www/html$ ls -l total 20 -rw-r--r-- 1 www-data www-data 389 janv. 5 08:53 eu.cfg -rwxr-xr-x 1 www-data www-data 634 janv. 7 08:32 index.esp -rwxr-xr-x 1 labo labo 21 janv. 5 09:55 phpinfo.php drwxr-xr-x 13 www-data www-data 4096 janv. 6 09:50 phpmyadmin
eu.cfg contains:
[all] -d E64 -eudir /usr/local/euphoria-4.1.0-Linux-x64 -i /usr/local/euphoria-4.1.0-Linux-x64/include -i /opt/vnf_test_tool/euphoria-mvc/include [translate] -arch ix86_64 -gcc -con -com /usr/local/euphoria-4.1.0-Linux-x64 -lib-pic /usr/local/euphoria-4.1.0-Linux-x64/bin/euso.a -lib /usr/local/euphoria-4.1.0-Linux-x64/bin/eu.a [bind] -eub /usr/local/euphoria-4.1.0-Linux-x64/bin/eub
Jean-Marc
4. Re: euphoria-mvc - app:run()
- Posted by jmduro Jan 07, 2021
- 852 views
Oops, I removed the templates directory when I made some cleaning on my document root folder!
After recreating the templates folder and the index.html file, everything is OK now!
So finally, here are some recommendations:
- verify Apache modules alias, actions and rewrite are loaded: sudo a2query -m | sort
- if not enable them: sudo a2enmod actions; sudo a2enmod alias; sudo a2enmod rewrite
- put Add CGI Handler instructions in a file named /etc/apache2/conf-available/eui4.1.conf
- enable the configuration: sudo a2enconf eui4.1
- reload Apache configuration: sudo systemctl reload apache2
Jean-Marc
5. Re: euphoria-mvc - app:run()
- Posted by jmduro Jan 07, 2021
- 820 views
Sorry,I was rather too quick. index.esp on Apache still shows the source script instead of executing it.
app:run()
It works with the development server with the same code.
server:start("0.0.0.0", 8080)
Jean-Marc
6. Re: euphoria-mvc - app:run()
- Posted by jmduro Jan 07, 2021
- 839 views
Running index.esp directly shows the same error:
$ eui index.esp Status: 404 Not Found Content-Length: 208 <!DOCTYPE html> <html> <head> <title>404 Not Found</title> </head> <body> <h1>404 Not Found</h1> <p>The requested URL was not found on this server.</p> <hr> <p><em>Apache</em></p> </body> </html>
7. Re: euphoria-mvc - app:run()
- Posted by ghaberek (admin) Jan 07, 2021
- 813 views
Oops, I removed the templates directory when I made some cleaning on my document root folder!
After recreating the templates folder and the index.html file, everything is OK now!
So finally, here are some recommendations:
- verify Apache modules alias, actions and rewrite are loaded: sudo a2query -m | sort
- if not enable them: sudo a2enmod actions; sudo a2enmod alias; sudo a2enmod rewrite
- put Add CGI Handler instructions in a file named /etc/apache2/conf-available/eui4.1.conf
- enable the configuration: sudo a2enconf eui4.1
- reload Apache configuration: sudo systemctl reload apache2
Unfortunately, given the Swiss-army-tool nature of Apache, it's hard to debug each particular configuration. This is especially true if it's been modified in some way from the defaults (i.e. you've installing phpMyAdmin or already running another website). Even the default configurations provided between distros and their releases can be different, which is especially frustrating (e.g. Debian uses apache2.conf but RHEL uses httpd.conf). It's for these reason that I'm trying to limit asking the user to configure anything directly in apache2.conf (or /etc/apache2/conf.d) unless absolutely necessary. I'm looking for sane defaults here. I would recommend undoing these changes and limit yourself to only enabling the required modules and adding configurations via .htaccess instead.
Running index.esp directly shows the same error:
$ eui index.esp Status: 404 Not Found Content-Length: 208 <!DOCTYPE html> <html> <head> <title>404 Not Found</title> </head> <body> <h1>404 Not Found</h1> <p>The requested URL was not found on this server.</p> <hr> <p><em>Apache</em></p> </body> </html>
The route parser expects certain environment variables to come from the web server when making CGI calls, at the very least it needs PATH_INFO (the requested path) and REQUEST_METHOD (like GET or POST). If your index.esp is correctly marked as executable, you should be able to test the CGI mode like this:
$ PATH_INFO=/ REQUEST_METHOD=GET ./index.esp
And you should get a proper response with Content-Type and Content-Length followed by the output from your index() route handler.
Make sure you're not missing the Options +ExecCGI directive and that mod_cgi and mod_mime are enabled (these are required for AddHandler to work correctly).
-Greg