How to structure a onion web application

47 views
Skip to first unread message

ahmed...@gmail.com

unread,
Dec 14, 2018, 6:14:52 AM12/14/18
to onion-dev, mono...@gmail.com
Hi there,
 
Very much new in onion and so on doing web-dev with C.
I want to build a web application in onion which will serve the index page as starting and every html page will have some ajax function call,for which I have to include some .js file in them.(also .css)
I have made two way to make this happen. I want better suggestions on which process,this is ought to be used and with which way, I will have less trouble in further to maintain more coding.

With process 1, I have as like following folder structure(more resources than that) in where, I write the following code in main.c

WEBAPP/SRC
--main.c
--index.html /* have js functions*/
--index_html.c
--Assets/
--css/
--style.css
--js/
--jquery.js
--Images/
--logo.png
--avatar.jpg
--page1.html  /* have js functions*/
--page1_html.c

o=onion_new(O_POOL);
onion_url *root = onion_root_url(o);

onion_url_add_handler(root, "^Assets", onion_handler_export_local_new("Assets"));
onion_url_add_handler(root, "^Images", onion_handler_export_local_new("Images"));
onion_url_add(root, "index", index_page);
onion_url_add(root, "page1", page1_handler);
onion_url_add_with_data(root, "", onion_shortcut_internal_redirect,
                          "index", NULL);

With process 2, I made a static folder as same as example given in oterm, I made this with opack but my data file become so large(110mib), that every when I run a Cmake, it takes more time to build than usual.
WEBAPP/SRC
--main.c
                              --assets.h
                      --opack_data.c 
 --Static/
--index.html /* have js functions*/
--Assets/
--css/
--style.css
--js/
--jquery.js
--Images/
--logo.png
--avatar.jpg
--page1.html /* have js functions*/
                       
 
onion_url *url = onion_url_new();
onion_url_add(url, "^Static/", opack_static);
onion_url_add_with_data(url, "", onion_shortcut_internal_redirect,
                          "static/index.html", NULL);

I have seen this example but this one doesn't include any resources to the html which is not a help for me. Can you suggest me any example code or example project which will help me to decide with my project structure.

David Moreno Montero

unread,
Dec 27, 2018, 10:33:13 AM12/27/18
to ahmed...@gmail.com, onion-dev, mono...@gmail.com
Hi,

sorry for the late reply, but I'm quite busy on the moment.

Anyway, I would use opack (as in https://github.com/davidmoreno/onion/blob/master/examples/oterm/), if the data files are not that big.

But 110MB sounds like a lot and maybe you should just refer to static files in the filesystem, and not have everything in just one binary. To do it, use `onion_handler_local_export_new(path)` like in https://github.com/davidmoreno/onion/tree/master/examples/userver.

An idea that just occured to me is that you can compress with gz the files, and serve them adding the compressed with gzip header, but you will need to use your own handlers, based on the ones that opack generates. If you sever mainly text, it could save quite a lot of space.

Regards,
David.


--
You received this message because you are subscribed to the Google Groups "onion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onion-dev+...@coralbits.com.
To post to this group, send email to onio...@coralbits.com.
Visit this group at https://groups.google.com/a/coralbits.com/group/onion-dev/.
For more options, visit https://groups.google.com/a/coralbits.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages