javascript - NanoHTTPD in Android serving multiple files webpage -



javascript - NanoHTTPD in Android serving multiple files webpage -

i using nanohttpd in android application serve webpage forced hosted in server, can't load straight webview.

if load single html file, server , client works.

if serve index.html includes javascript files error of chromium (crosswalk) per included js file:

06-24 17:27:28.473: i/chromium(16287): [info:console(1)] "uncaught syntaxerror: unexpected end of input", source: http://localhost:8080/interface.js (1)

i thought problem not giving right mime type in these cases changed code in order stills failing:

private class webserver extends nanohttpd { public static final string mime_javascript = "text/javascript"; public static final string mime_css = "text/css"; public webserver() { super(8080); } @override public response serve(ihttpsession session) { string mime_type = nanohttpd.mime_html; method method = session.getmethod(); string uri = session.geturi(); system.out.println(method + " '" + uri + "' "); string reply = ""; if(method.tostring().equalsignorecase("get")){ string path; if(uri.equals("/")){ path="/index.html"; }else{ path = uri; try{ if(path.substring(path.length()-2, path.length()).equalsignorecase("js")){ mime_type = mime_javascript; }else if(path.substring(path.length()-3, path.length()).equalsignorecase("css")){ mime_type = mime_css; } }catch(exception e){ } } seek { // open file sd card inputstream descriptor = getassets().open("www/attitude"+path); inputstreamreader index = new inputstreamreader(descriptor); bufferedreader reader = new bufferedreader(index); string line = ""; while ((line = reader.readline()) != null) { reply += line; } reader.close(); } catch(ioexception ioe) { log.w("httpd", ioe.tostring()); } } homecoming new nanohttpd.response( response.status.ok,mime_type,answer); } }

my javascript files contain straight functions, e.g. init.js:

function init() { setloadingprogress(1); //setloadingprogress(15); initscene(); //setloadingprogress(35); setloadingprogress(5); initreference(); initangles(); //setloadingprogress(65); setloadingprogress(10); initindicators(); //setloadingprogress(75); setloadingprogress(13); initsun(); //setloadingprogress(85); setloadingprogress(15); initearth(); changeview(selected_view); //setloadingprogress(100); setloadingprogress(18);

}

i take simpler ways serve multi-file webpage in same android application client other nanohttpd.

my purpose skip restriction of having server hosting webpage, guess many other people want know how utilize class complex webpages.

thanks.

edit 1: new code many mime type detection

public static final string mime_javascript = "text/javascript"; public static final string mime_css = "text/css"; public static final string mime_jpeg = "image/jpeg"; public static final string mime_png = "image/png"; public static final string mime_svg = "image/svg+xml"; public static final string mime_json = "application/json"; @override public response serve(ihttpsession session) { string mime_type = nanohttpd.mime_html; method method = session.getmethod(); string uri = session.geturi(); system.out.println(method + " '" + uri + "' "); inputstream descriptor = null; if(method.tostring().equalsignorecase("get")){ string path; if(uri.equals("/")){ path="/index.html"; }else{ path = uri; try{ if(path.endswith(".js")){ mime_type = mime_javascript; }else if(path.endswith(".css")){ mime_type = mime_css; }else if(path.endswith(".html")){ mime_type = mime_html; }else if(path.endswith(".jpeg")){ mime_type = mime_jpeg; }else if(path.endswith(".png")){ mime_type = mime_png; }else if(path.endswith(".jpg")){ mime_type = mime_jpeg; }else if(path.endswith(".svg")){ mime_type = mime_svg; }else if(path.endswith(".json")){ mime_type = mime_json; } }catch(exception e){ } } seek { // open file sd card descriptor = getassets().open("www/orbit"+path); } catch(ioexception ioe) { log.w("httpd", ioe.tostring()); } } homecoming new nanohttpd.response( response.status.ok,mime_type,descriptor); }

it crashes error:

06-25 10:27:03.470: i/system.out(19604): '/cesium/workers/cesiumworkerbootstrapper.js' 06-25 10:27:03.480: i/system.out(19604): '/cesium/workers/transfertypedarraytest.js' 06-25 10:27:03.520: i/system.out(19604): '/cesium/assets/textures/moonsmall.jpg' 06-25 10:27:03.550: i/system.out(19604): '/cesium/assets/textures/skybox/tycho2t3_80_py.jpg' 06-25 10:27:03.550: i/system.out(19604): '/cesium/assets/textures/skybox/tycho2t3_80_my.jpg' 06-25 10:27:03.550: i/system.out(19604): '/cesium/assets/textures/skybox/tycho2t3_80_pz.jpg' 06-25 10:27:03.560: i/system.out(19604): '/cesium/assets/textures/skybox/tycho2t3_80_mx.jpg' 06-25 10:27:03.560: i/system.out(19604): '/cesium/assets/textures/skybox/tycho2t3_80_px.jpg' 06-25 10:27:03.570: i/system.out(19604): '/cesium/assets/textures/skybox/tycho2t3_80_mz.jpg' 06-25 10:27:03.980: a/libc(19604): fatal signal 11 (sigsegv) @ 0x00000080 (code=1), thread 19696 (chrome_inprocgp)

if open illustration debug console of browser opened see next not executed. image/png of fields status different otherones. there .js files application/javascript , others application/x-javascript

cesiumjs.org/cesium/build/helloworld.html

javascript android html nanohttpd

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -