1. Euphoria MVC updates
- Posted by ghaberek (admin) Feb 10, 2020
- 4360 views
- Last edited 3 months ago
I committed several improvements to Euphoria MVC today.
https://github.com/OpenEuphoria/euphoria-mvc
- Built-in web server now supports GET and POST requests.
- Model library can now query/insert/update/delete objects.
- Template library does better at handling more expressions.
- Route parser now accepts arbitrary regex patterns for type-checking.
- Added libraries for parsing HTML and JSON documents.
- Easily save and load configuration files (in INI format).
- Wrappers for MySQL (or MariaDB), SQLite3, and libcurl.
- Updated documentations!
Update 11/15/2020:
- Added SQLite3 library and wrapper
Update 11/23/2020:
- Added HTML parser
Update 11/28/2020:
- Overhauled mvc/config.e
There's still a lot to do. But I'm still working on it. I'm not dead yet!
-Greg
2. Re: Euphoria MVC updates
- Posted by Icy_Viking Feb 10, 2020
- 4324 views
I committed several improvements to Euphoria MVC today.
https://github.com/OpenEuphoria/euphoria-mvc
- Built-in web server now supports GET and POST requests.
- Model library can now query/insert/update/delete objects.
- Template library does better at handling more expressions.
- Route parser now accepts arbitrary regex patterns for type-checking.
- Updated documentations!
There's still a lot to do. But I'm still working on it. I'm not dead yet!
-Greg
Sounds great Greg. Hopefully thew new site will be up sometime this year.
3. Re: Euphoria MVC updates
- Posted by jimcbrown (admin) Feb 18, 2020
- 4059 views
I committed several improvements to Euphoria MVC today.
https://github.com/OpenEuphoria/euphoria-mvc
- Built-in web server now supports GET and POST requests.
- Model library can now query/insert/update/delete objects.
- Template library does better at handling more expressions.
- Route parser now accepts arbitrary regex patterns for type-checking.
- Updated documentations!
There's still a lot to do. But I'm still working on it. I'm not dead yet!
-Greg
Sounds great Greg.
Agreed! Can't wait to see this when it's finally ready to be rolled out.
Hopefully thew new site will be up sometime this year.
Fingers crossed.
4. Re: Euphoria MVC updates
- Posted by ghaberek (admin) in July
- 3760 views
I added a JSON parser today! (Well, I actually wrote it a month ago.)
Source: https://github.com/OpenEuphoria/euphoria-mvc/blob/v1.8.0/include/mvc/json.e
Docs: https://github.com/OpenEuphoria/euphoria-mvc/blob/v1.8.0/docs/JSON.md
Edit: the docs reference Euphoria maps but I stripped all of that out to simplify the parser. Objects are just sequences of {key,{type,value}} items now. That's why I added json_fetch to look up values from keys. I'll update the documentation to remove references to maps soon.
-Greg
5. Re: Euphoria MVC updates
- Posted by ghaberek (admin) in September
- 2411 views
I added a CURL wrapper today! (Well, I actually wrote it several years ago to make the existing euweb work with reCAPTCHAv2.) Updated release to v1.9.0.
https://github.com/OpenEuphoria/euphoria-mvc/releases/tag/v1.9.0
-Greg
6. Re: Euphoria MVC updates
- Posted by ghaberek (admin) in September
- 2125 views
I added a lot more CURL functions and a few more JSON functions and updated the documentation a bit. Updated release to v1.10.0.
https://github.com/OpenEuphoria/euphoria-mvc/releases/tag/v1.10.0
-Greg
7. Re: Euphoria MVC updates
- Posted by SDPringle in September
- 2089 views
That's funny Greg. I built an importer that would load in the constants and functions from a C- header file and create a Euphoria E file for in order to create a curl wrapper. Is it necessary to use MVC in order to use the CURL function?
SD Pringle
8. Re: Euphoria MVC updates
- Posted by ghaberek (admin) in September
- 2070 views
That's funny Greg. I built an importer that would load in the constants and functions from a C- header file and create a Euphoria E file for in order to create a curl wrapper. Is it necessary to use MVC in order to use the CURL function?
Nope, it's entirely separate and in its own directory. It's just so integral to building web apps that I figured I would just include it directly.
I wrapped the whole thing by hand and made some improvements from when I originally wrote it a couple years ago.
Anyone who needs it can just copy the files from here: https://github.com/OpenEuphoria/euphoria-mvc/tree/master/include/curl
I also have some basic documentation here: https://github.com/OpenEuphoria/euphoria-mvc/blob/master/docs/CURL.md (including where best to get Windows binaries!)
-Greg
9. Re: Euphoria MVC updates
- Posted by SDPringle in September
- 2017 views
The failing t_net_http.e has been a thorn in my side for years now and it is a bigger waste of time to me to re-implement what CURL from (Euphoria MVC) already does in Euphoria than to leverage CURL it in order to fix t_net_http. I wouldn't mind if std/net/http.e went away completely at this point and I don't see anyone really using it. I am the kind of person who doesn't like to remove something from a library once it is already in there, though. What do you think?
Forked into: RM std/net/http.e?
10. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 1132 views
I've added a SQLite3 wrapper and lots of little updates here and there.
https://github.com/OpenEuphoria/euphoria-mvc/releases/tag/v1.11.0
-Greg
11. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 1001 views
I've added an HTML parser a few minor fixes.
https://github.com/OpenEuphoria/euphoria-mvc/releases/tag/v1.12.0
-Greg
12. Re: Euphoria MVC updates
- Posted by jmduro 3 months ago
- 954 views
It's really nice.
I found a bug with session cookies so I opened a new issue.
Regards
Jean-Marc
13. Re: Euphoria MVC updates
- Posted by jmduro 3 months ago
- 954 views
Where should local CSS files be located to be used with the development server ?
Jean-Marc
14. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 933 views
It's really nice.
Thanks! That's good to hear.
I found a bug with session cookies so I opened a new issue.
Thanks, I will look into this. Unfortunately some the older code is in need of better testing and cleanup.
FYI on GitHub you can enclose blocks of code in triple backticks ``` or by indenting at least four spaces.
-Greg
15. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 937 views
Where should local CSS files be located to be used with the development server ?
Yeah I need to add a feature for serving files directly from a local directory. I'd also like to add an option for "base directory" so you can change it from current directory.
In the mean time, I've at least added send_file() and download_file() which are shorthand for verifying a file exists, looking up its mime-type, and then sending the required headers.
include mvc/app.e
download_file( sequence filename, sequence path=filename ) - Return the contents of a file and prompt the browser to download it.
I pushed the commit for adding send_file() just now: https://github.com/OpenEuphoria/euphoria-mvc/releases/tag/v1.12.1
You can use this to add a static route handler to your application. Then just put everything in /static/, like /static/css/, /static/js/, etc.
Edit: Or you can add a route pattern for specific directories as I've indicated below.
include std/map.e include mvc/app.e include std/filesys.e -- for canonical_path() include std/search.e -- for search:begins() -- -- Route handler for files in /static/ -- function static( object request ) -- get the path to the requested file sequence path_info = map:get( request, "PATH_INFO" ) -- -- Note: path_info will always start with -- "/static/" thanks to the route handler. -- -- ensure the local file is an actual full path sequence local_file = canonical_path( "." & path_info ) -- ensure the local file exists in current directory if search:begins( current_dir(), local_file ) then -- go ahead and send the file to the browser return send_file( local_path ) end if -- tell the browser the file doesn't exist return response_code( 404 ) end function -- -- Note: this pattern should resolve to "static" and find the function above. If not, you can call -- app:route("pattern", "func name") or even app:route("pattern", "func name", routine_id("func name")) -- app:route( "/static/.+" ) -- Or add a handler for specific directories like this: app:route( "/(css|js|fonts|images)/.+", "static" )
-Greg
16. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 923 views
Where should local CSS files be located to be used with the development server ?
I should also point out for anyone reading along that if you're using Apache or Nginx, it should serve static files directly on your behalf. Routing them through your app would add unnecessary complications and slow everything down a bit.
-Greg
17. Re: Euphoria MVC updates
- Posted by jmduro 3 months ago
- 872 views
sequence local_file = canonical_path( "." & path_info ) if search:begins( current_dir(), local_file ) then return send_file( local_path ) end if
local_path is not defined. I thought it could be local_file instead but that's wrong:
2020/11/26 11:41:13 INFO static@mysql_users.ex:22 path_info = "\"/static/css/w3.css\"" 2020/11/26 11:41:13 INFO static@mysql_users.ex:31 local_file = "\"C:\\\\Users\\\\duro\\\\Documents\\\\mysql_users\\\\examples\\\\static\\\\css\\\\w3.css\"" 2020/11/26 11:41:13 INFO client_handler@server.e:140 "127.0.0.1" "GET" "/static/css/w3.css" "404 Not Found"Jean-Marc
18. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 854 views
local_path is not defined.
Yes, a typo on my part, sorry about that.
I thought it could be local_file instead but that's wrong:
2020/11/26 11:41:13 INFO static@mysql_users.ex:22 path_info = "\"/static/css/w3.css\"" 2020/11/26 11:41:13 INFO static@mysql_users.ex:31 local_file = "\"C:\\\\Users\\\\duro\\\\Documents\\\\mysql_users\\\\examples\\\\static\\\\css\\\\w3.css\"" 2020/11/26 11:41:13 INFO client_handler@server.e:140 "127.0.0.1" "GET" "/static/css/w3.css" "404 Not Found"
No, that's right. The problem in the example you provided is that "static" is not in the "examples" directory, so the file indeed does not exist.
This is the layout of the zip file you posted:
mysql_users\ examples\ mysql.e mysql_users.ex static\ css\ w3.css templates\ insert.html login.html main.html users.html libmariadb.dll users.sql
I recommend putting the main app file in the root directory for your project, and then other directories like "static" and "templates" can be easily referenced from there.
So your project should look more like this:
mysql_users\ static\ css\ w3.css templates\ insert.html login.html main.html users.html libmariadb.dll mysql.e mysql_users.ex users.sql
And then run:
eui mysql_users.ex
And your static route will find the correct path to "w3.css"
Logging Targets
The logger outputs to STDERR by default. You're changing this to "debug.log" which is helpful, but you can also target multiple outputs, like this:
set_log_output({ STDOUT, "debug.log" })
When writing to files, the logger defaults to append mode. If you want to overwrite the file each time, prepend the filename with an exclamation mark:
set_log_output({ STDOUT, "!debug.log" }) -- overwrite debug.log each time
Part of the idea of the logger is to have it color-code its output to the console to make it easier to read in real-time while the application is running.
Logging Formats
You don't need to pretty-print data you send to the logger routines. They're already built to pretty-print anything that isn't already a string. So you're just needlessly double-escaping things like quotes and backslashes,
So you can change this:
sequence path_info = map:get( request, "PATH_INFO" ) log_info( "path_info = %s", {pretty_sprint(path_info, {2})} )
2020/11/26 11:41:13 INFO static@mysql_users.ex:22 path_info = "\"/static/css/w3.css\"" 2020/11/26 11:41:13 INFO static@mysql_users.ex:31 local_file = "\"C:\\\\Users\\\\duro\\\\Documents\\\\mysql_users\\\\examples\\\\static\\\\css\\\\w3.css\""
To just this:
sequence path_info = map:get( request, "PATH_INFO" ) log_info( "path_info = %s", {path_info} )
2020/11/26 11:41:13 INFO static@mysql_users.ex:22 path_info = "/static/css/w3.css" 2020/11/26 11:41:13 INFO static@mysql_users.ex:31 local_file = "C:\\Users\\duro\\Documents\\mysql_users\\examples\\static\\css\\w3.css"
Part of the idea of Euphoria MVC is to reduce the friction on these kinds of things and help you write cleaner, simpler code.
-Greg
19. Re: Euphoria MVC updates
- Posted by jmduro 3 months ago
- 802 views
Thank you Greg,
I updated my MySQL example for euphoria-mvc: http://jean-marc.duro.pagesperso-orange.fr/mysql_users.zip
euphoria-mvc is a real game-changer in web programming for me.
Jean-Marc
20. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 741 views
I updated my MySQL example for euphoria-mvc: http://jean-marc.duro.pagesperso-orange.fr/mysql_users.zip
Thanks, I'll take a look at it!
euphoria-mvc is a real game-changer in web programming for me.
That's great to hear. I hope you get some good use out of it and please don't hesitate to ask questions here. Bug fixes and feature requests can be issues over on GitHub.
-Greg
21. Re: Euphoria MVC updates
- Posted by ghaberek (admin) 3 months ago
- 740 views
I overhauled mvc/config.e today.
https://github.com/OpenEuphoria/euphoria-mvc/releases/tag/v1.13.0
If your configuration looks like this:
# app.cfg [database] name = mydatabase username = dbuser password = abc123 host = db1.example.com
You can load it in your app like this:
include mvc/config.e include mvc/logger.e if not load_config( "app.cfg" ) then log_crash( "Failed to load configuration" ) end if sequence db_host, db_name, db_user, db_pass db_host = get_config( "database.host" ) db_name = get_config( "database.name" ) db_user = get_config( "database.username" ) db_pass = get_config( "database.password" )
And it will even preserve comments when saving!
-Greg