css and js files

109 views
Skip to first unread message

Andries

unread,
Oct 29, 2012, 4:28:03 PM10/29/12
to nx...@googlegroups.com
Hi Yaroslav,

How can I use css and js files? I tried to do this with the .dir parameter, but no result so far.

Yaroslav

unread,
Oct 29, 2012, 5:13:39 PM10/29/12
to nx...@googlegroups.com
Hi Andries,

What exactly do you mean by 'use'? What are you trying to achieve?

Yaroslav

Andries

unread,
Oct 30, 2012, 11:13:17 AM10/30/12
to nx...@googlegroups.com
I will explain it with an example:
<link rel="stylesheet" type="text/css" href="cssdir/cssfile.css" />

Using this example, I added cssdir with csfilecss in it under www/root. To my handler, I added a .dir=www/root parameter, but the css file is not found when executing the program. The html is all rendered within the c-program.

Where do I need to put the css file so it can be loaded into the HTML-code? Do I need to make the path relative to where the c-program is located?

Thx,
Andries

Op maandag 29 oktober 2012 22:13:39 UTC+1 schreef Yaroslav het volgende:

Yaroslav

unread,
Oct 30, 2012, 3:15:14 PM10/30/12
to nx...@googlegroups.com
Andries,

If you specify .dir path as relative (no leading slash) it should be relative to nxweb working directory. It is the directory you launch nxweb from (unless you override it with command line option).

Yaroslav

Andries Arijs

unread,
Oct 30, 2012, 3:41:39 PM10/30/12
to nx...@googlegroups.com
Yaroslav,

I can't get this to work. I also tried with the absolute path starting from root.

Do I need to compile the css file also? Because I only compile the c files at this moment.

I tried also the following:
bin/modules/index.c ==> in this file i specify the htmlcode for cssdir/cssfile.css
bin/modules/cssdir/cssfile.css

This also doesn't load the css file.

Andries

2012/10/30 Yaroslav <yar...@gmail.com>

Yaroslav

unread,
Oct 30, 2012, 4:22:12 PM10/30/12
to nx...@googlegroups.com
Before making changes to project's code did you manage to run default nxweb configuration? It should serve index.htm from www/root directory.

Andries

unread,
Nov 14, 2012, 1:12:23 PM11/14/12
to nx...@googlegroups.com
Hi Yaroslav,

I apologize for the late reply, but I didn't have much time the last weeks.

I tried with the default configuration as you mentioned, but when I run http://localhost/index.htm it returns an 404 error.

Do I need to set a workdir in the configuration file?

Andries

unread,
Nov 14, 2012, 1:29:41 PM11/14/12
to nx...@googlegroups.com
The index.htm is working now (I used the full path in .dir).

Op woensdag 14 november 2012 19:12:23 UTC+1 schreef Andries het volgende:

Andries

unread,
Nov 14, 2012, 2:00:23 PM11/14/12
to nx...@googlegroups.com
Here is what I did:

The handler in main.c:
NXWEB_SET_HANDLER(index, "/index", &index_handler, .priority=100000,.dir="/my/path/www/root");

c-code:
#define CSSDIR "testcss"
#define CSSFILE "file.css"
...
nxweb_response_append_str(resp, "<!DOCTYPE html>");
nxweb_response_append_str(resp, "<html>");
nxweb_response_append_str(resp, "<head>");
nxweb_response_append_str(resp, "<meta charset= \"utf-8\" />");
nxweb_response_printf(resp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s/%s\" />", CSSDIR, CSSFILE);
nxweb_response_append_str(resp, "<title>Test</title>");
nxweb_response_append_str(resp, "</head>");
nxweb_response_append_str(resp, "<body>");
nxweb_response_append_str(resp, "Test");
nxweb_response_append_str(resp, "</body>");
nxweb_response_append_str(resp, "</html>");

The testcss/file.css directory is located under www/root .


Op woensdag 14 november 2012 19:29:42 UTC+1 schreef Andries het volgende:

Yaroslav

unread,
Nov 14, 2012, 4:28:28 PM11/14/12
to nx...@googlegroups.com
Hi Andries,

NXWEB_SET_HANDLER(index, "/index", &index_handler, .priority=100000,.dir="/my/path/www/root");

This is your custom handler "index_handler" assigned to handle requests starting with prefix "/index". .dir option has no meaning here unless your handler makes use of it.

If you want some static files accessible through nxweb make sure you have "sendfile_handler" assigned as well. Also make sure sendfile handler has lower priority (higher .priority value) than your handler so they get processed in right order.

Yaroslav

Andries

unread,
Nov 15, 2012, 11:57:44 AM11/15/12
to nx...@googlegroups.com
Thanks Yaroslav, this works :).

Andries

unread,
Apr 12, 2014, 4:50:47 PM4/12/14
to nx...@googlegroups.com
Yaroslav,

With the nxweb_config.json file, how can I set static files?

I tried this, but this doesn't work:
"routing":[
  {
  "prefix":null, "handler":"my_handler", "dir":"/path/to/static/dir", "memcache":true, "charset":"utf-8"
  }
]

Do I need to make a handler for static files too (i saw a mime.c file in the libraries)?

Yaroslav

unread,
Apr 12, 2014, 5:02:44 PM4/12/14
to nx...@googlegroups.com
There is sendfile handler for static files in nxweb. See default config for example.


--
You received this message because you are subscribed to the Google Groups "nxweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nxweb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages