public static String[] staticFilesPath() { return GLOBAL.staticFilesPath(); }
public static void staticFilesPath(String... staticFilesPath) { GLOBAL.staticFilesPath(staticFilesPath); }
public String[] staticFilesPath() { return staticFilesPath != null || defaults == null ? staticFilesPath : defaults.staticFilesPath(); }
@Override public boolean hasRouteOrResource(HttpVerb verb, String uri) { if (verb == HttpVerb.GET) { String[] staticFilesLocations = custom().staticFilesPath(); if (U.notEmpty(staticFilesLocations)) { String filename = Str.triml(uri, '/'); if (filename.isEmpty()) filename = "index.html"; if (Res.from(filename, staticFilesLocations).exists()) return true; } } return find(verb, uri) != null; }
@Override public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) { if (!HttpUtils.isGetReq(req)) return HttpStatus.NOT_FOUND; try { String[] staticFilesLocations = customization.staticFilesPath(); if (!U.isEmpty(staticFilesLocations)) { Res res = HttpUtils.staticResource(req, staticFilesLocations); if (res != null) { StaticFilesSecurity staticFilesSecurity = customization.staticFilesSecurity(); if (staticFilesSecurity.canServe(req, res)) { byte[] bytes = res.getBytesOrNull(); if (bytes != null) { MediaType contentType = U.or(MediaType.getByFileName(res.getName()), MediaType.BINARY); HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, bytes); return HttpStatus.DONE; } } } } return HttpStatus.NOT_FOUND; } catch (Exception e) { return HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR); } }
private synchronized void listen() { if (!listening && !reloaded) { App.inferCallers(); listening = true; HttpProcessor proc = processor != null ? processor : http(); if (Env.dev() && !On.changes().isIgnored() && MscOpts.hasRapidoidWatch()) { proc = new AppRestartProcessor(this, proc); On.changes().byDefaultRestart(); } if (server == null) { int targetPort = port(); server = proc.listen(address(), targetPort); Log.info("!Server has started", "setup", name(), "!home", "http://localhost:" + targetPort); Log.info("!Static resources will be served from the following locations", "setup", name(), "!locations", custom().staticFilesPath()); } } }
public static void reset() { synchronized (GLOBAL) { GLOBAL.reset(); GLOBAL.staticFilesPath(Defaults.staticFilesPath()); GLOBAL.errorHandler(Defaults.errorHandler()); GLOBAL.viewResolver(Defaults.viewResolver()); GLOBAL.pageDecorator(Defaults.pageDecorator()); GLOBAL.jsonResponseRenderer(Defaults.jsonResponseRenderer()); GLOBAL.jsonRequestBodyParser(Defaults.jsonRequestBodyParser()); GLOBAL.xmlResponseRenderer(Defaults.xmlResponseRenderer()); GLOBAL.xmlRequestBodyParser(Defaults.xmlRequestBodyParser()); GLOBAL.beanParameterFactory(Defaults.beanParameterFactory()); GLOBAL.loginProvider(Defaults.loginProvider()); GLOBAL.rolesProvider(Defaults.rolesProvider()); GLOBAL.validator(Defaults.validator()); GLOBAL.objectMapper(Defaults.objectMapper()); GLOBAL.xmlMapper(Defaults.xmlMapper()); GLOBAL.entityManagerFactoryProvider(Defaults.entityManagerFactoryProvider()); GLOBAL.entityManagerProvider(Defaults.entityManagerProvider()); GLOBAL.sessionManager(Defaults.sessionManager()); GLOBAL.staticFilesSecurity(Defaults.staticFilesSecurity()); GLOBAL.wrappers(Defaults.wrappers()); GLOBAL.templateLoader(Defaults.templateLoader()); } }
public String[] staticFilesPath() { return staticFilesPath != null || defaults == null ? staticFilesPath : defaults.staticFilesPath(); }
public static String[] staticFilesPath() { return GLOBAL.staticFilesPath(); }
public static void staticFilesPath(String... staticFilesPath) { GLOBAL.staticFilesPath(staticFilesPath); }
@Override public boolean hasRouteOrResource(HttpVerb verb, String uri) { if (verb == HttpVerb.GET) { String[] staticFilesLocations = custom().staticFilesPath(); if (U.notEmpty(staticFilesLocations)) { String filename = Str.triml(uri, '/'); if (filename.isEmpty()) filename = "index.html"; if (Res.from(filename, staticFilesLocations).exists()) return true; } } return find(verb, uri) != null; }
@Override public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) { if (!HttpUtils.isGetReq(req)) return HttpStatus.NOT_FOUND; try { String[] staticFilesLocations = customization.staticFilesPath(); if (!U.isEmpty(staticFilesLocations)) { Res res = HttpUtils.staticResource(req, staticFilesLocations); if (res != null) { StaticFilesSecurity staticFilesSecurity = customization.staticFilesSecurity(); if (staticFilesSecurity.canServe(req, res)) { byte[] bytes = res.getBytesOrNull(); if (bytes != null) { MediaType contentType = U.or(MediaType.getByFileName(res.getName()), MediaType.BINARY); HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, bytes); return HttpStatus.DONE; } } } } return HttpStatus.NOT_FOUND; } catch (Exception e) { return HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR); } }
private synchronized void listen() { if (!listening && !reloaded) { App.inferCallers(); listening = true; HttpProcessor proc = processor != null ? processor : http(); if (Env.dev() && !On.changes().isIgnored() && MscOpts.hasRapidoidWatch()) { proc = new AppRestartProcessor(this, proc); On.changes().byDefaultRestart(); } if (delegateAdminToApp()) { server = on().server(); } else if (delegateAppToAdmin()) { server = admin().server(); } if (server == null) { int targetPort; if (isAppOrAdminOnSameServer()) { targetPort = on().port(); server = proc.listen(on().address(), targetPort); } else { targetPort = port(); server = proc.listen(address(), targetPort); } Log.info("!Server has started", "setup", name(), "!home", "http://localhost:" + targetPort); Log.info("!Static resources will be served from the following locations", "setup", name(), "!locations", custom().staticFilesPath()); } } }
public static void reset() { synchronized (GLOBAL) { GLOBAL.reset(); GLOBAL.staticFilesPath(Defaults.staticFilesPath()); GLOBAL.errorHandler(Defaults.errorHandler()); GLOBAL.viewResolver(Defaults.viewResolver()); GLOBAL.pageDecorator(Defaults.pageDecorator()); GLOBAL.jsonResponseRenderer(Defaults.jsonResponseRenderer()); GLOBAL.jsonRequestBodyParser(Defaults.jsonRequestBodyParser()); GLOBAL.xmlResponseRenderer(Defaults.xmlResponseRenderer()); GLOBAL.xmlRequestBodyParser(Defaults.xmlRequestBodyParser()); GLOBAL.beanParameterFactory(Defaults.beanParameterFactory()); GLOBAL.loginProvider(Defaults.loginProvider()); GLOBAL.rolesProvider(Defaults.rolesProvider()); GLOBAL.validator(Defaults.validator()); GLOBAL.objectMapper(Defaults.objectMapper()); GLOBAL.xmlMapper(Defaults.xmlMapper()); GLOBAL.entityManagerFactoryProvider(Defaults.entityManagerFactoryProvider()); GLOBAL.entityManagerProvider(Defaults.entityManagerProvider()); GLOBAL.sessionManager(Defaults.sessionManager()); GLOBAL.staticFilesSecurity(Defaults.staticFilesSecurity()); GLOBAL.wrappers(Defaults.wrappers()); GLOBAL.templateLoader(Defaults.templateLoader()); } }