ulfius_add_endpoint_by_val for files in folder #232
Replies: 1 comment
-
Hi @nicolasb565 , Unfortunately, Also, you can't pass a regexp in the
If you must use ulfius to provide static files, instead of using an apache or NGINX server instead, you can create a callback function that will behave like a static file reader though. Be careful, they may be overkill as is if your needs are more simple than that. In your case, a simple endpoint could start like this: ulfius_add_endpoint_by_val(&instance, "GET", "file", "*", 0, &callback_file, NULL);
int callback_file (const struct _u_request * request, struct _u_response * response, void * user_data) {
char path[1025] = {0}, ;
strcpy(path, "/path/to/directory/");
strcat(path, request->http_url, 1024-strlen("/path/to/directory/"));
FILE * f = fopen (path, "rb"); // be careful to check for directory traversal bugs
//...
} |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am wondering if there is a way to use ulfius_add_endpoint_by_val for all files inside a folder. For example this would be useful for assets like jpeg files. Can we use wildcard or regex?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions