node.js -> Mongoose C++ HTTP server. How do I call/send a JS module ? #1611
-
I'm transitioning some node.js code I wrote to the Mongoose C/C++ web server. I want to serve a static HTML page that calls a JavaScript module that is in a separate file. ie Page1.html has the following in it.
My Mongoose server serves up Page1.html, no problem. But Firefox throws an error when it loads the JS module:
I had the same problem in Node.js, but solved it by running node-static. https://www.npmjs.com/package/node-static
I have set mime_types:
How do I achieve the same functionality in Mongoose ? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
The device-dashboard example serves } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
...
if (mg_http_match_uri(hm, "/api/hi")) {
...
} else {
struct mg_http_serve_opts opts = {0};
opts.root_dir = "web_root";
mg_http_serve_dir(c, ev_data, &opts);
}
} Tutorials here |
Beta Was this translation helpful? Give feedback.
-
Your code serves the very same file for every request, when you ask for module.js the server will send page1.html because that is what you are telling it to do. |
Beta Was this translation helpful? Give feedback.
Your code serves the very same file for every request, when you ask for module.js the server will send page1.html because that is what you are telling it to do.
Please start from a tutorial and work your way up.