MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add user agent header by default

+16 -16
+8 -4
examples/server/server.js
··· 29 29 30 30 router.insert('/status', async c => { 31 31 await new Promise(resolve => setTimeout(resolve, 1000)); 32 - // const result = await Promise.resolve('Hello'); 33 - const result = (await fetch('http://localhost:8000/meow')).text(); 32 + const result = await Promise.resolve('Hello'); 34 33 return c.res.body(`server is responding with ${result}`); 35 34 }); 36 35 ··· 46 45 return c.res.json({ users: [] }); 47 46 }); 48 47 48 + router.insert('/zen', async c => { 49 + const response = await fetch('https://api.github.com/zen'); 50 + return c.res.body(response.body); 51 + }); 52 + 49 53 router.insert('/api/v2/demo', async c => { 50 - const data = (await fetch('https://themackabu.dev/test.json')).json(); 51 - return c.res.json(data); 54 + const data = await fetch('https://themackabu.dev/test.json'); 55 + return c.res.json(data.json()); 52 56 }); 53 57 54 58 router.insert('/files/*path', async c => {
+1 -1
meson.build
··· 67 67 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 68 68 69 69 version_conf = configuration_data() 70 - version_conf.set('ANT_VERSION', '0.0.6.27') 70 + version_conf.set('ANT_VERSION', '0.0.6.29') 71 71 version_conf.set('ANT_GIT_HASH', git_hash) 72 72 version_conf.set('ANT_BUILD_DATE', build_date) 73 73
+7 -11
src/modules/fetch.c
··· 7 7 #include <utarray.h> 8 8 #include <unistd.h> 9 9 10 + #include "config.h" 10 11 #include "runtime.h" 11 12 #include "modules/fetch.h" 12 13 #include "modules/timer.h" ··· 59 60 60 61 js_set(js, response_obj, "status", js_mknum(status)); 61 62 js_set(js, response_obj, "ok", status >= 200 && status < 300 ? js_mktrue() : js_mkfalse()); 62 - js_set(js, response_obj, "__body", js_mkstr(js, body, body_len)); 63 + js_set(js, response_obj, "body", js_mkstr(js, body, body_len)); 63 64 64 - const char *json_code = "(){return JSON.parse(this.__body)}"; 65 + const char *json_code = "(){return JSON.parse(this.body)}"; 65 66 jsval_t json_str = js_mkstr(js, json_code, strlen(json_code)); 66 67 jsval_t json_obj = js_mkobj(js); 67 68 js_set(js, json_obj, "__code", json_str); ··· 69 70 memcpy(&json_func, &json_obj, sizeof(jsval_t)); 70 71 json_func = (json_func & 0xFFFFFFFFFFFFULL) | (0x7FF0000000000000ULL | ((uint64_t)7 << 48)); 71 72 js_set(js, response_obj, "json", json_func); 72 - 73 - const char *text_code = "(){return this.__body}"; 74 - jsval_t text_str = js_mkstr(js, text_code, strlen(text_code)); 75 - jsval_t text_obj = js_mkobj(js); 76 - js_set(js, text_obj, "__code", text_str); 77 - jsval_t text_func = js_mknum(0); 78 - memcpy(&text_func, &text_obj, sizeof(jsval_t)); 79 - text_func = (text_func & 0xFFFFFFFFFFFFULL) | (0x7FF0000000000000ULL | ((uint64_t)7 << 48)); 80 - js_set(js, response_obj, "text", text_func); 81 73 82 74 return response_obj; 83 75 } ··· 263 255 } 264 256 265 257 req->http_req->data = req; 258 + 259 + char user_agent[256]; 260 + snprintf(user_agent, sizeof(user_agent), "ant/%s", ANT_VERSION); 261 + tlsuv_http_req_header(req->http_req, "User-Agent", user_agent); 266 262 267 263 if (js_type(options_val) != JS_UNDEF && js_type(options_val) != JS_NULL) { 268 264 jsval_t headers_val = js_get(js, options_val, "headers");