yanzhenjie / AndServer

:cherries: Web server and web framework of Android platform.
https://yanzhenjie.com/AndServer
Apache License 2.0
3.7k stars 746 forks source link

如何添加多个website同时生效 #294

Open CleverSJX opened 4 years ago

CleverSJX commented 4 years ago

问题

我想同时支持文件浏览和assets,下面这样配置我访问 ip:port 默认访问的是第一个添加的website 如何让同时生效呢?

例如给每个website设置单独的入口

@Config
public class AppWebConfig implements WebConfig {

    @Override
    public void onConfig(Context context, Delegate delegate) {
        delegate.addWebsite(new FileBrowser(PathUtils.getInternalAppFilesPath()));
        delegate.addWebsite(new AssetsWebsite(context, "/web"));
    }
}
ChadDaBin commented 3 years ago

同问! @yanzhenjie

yanzhenjie commented 3 years ago

本身就是同时生效的,但是每个Website的路径不能重复,如果有重复的,会以第一个搜索到的路径为准。

tom110 commented 3 years ago

能给个例子吗?感觉升级以后以前的文档用不上了啊,而且simple貌似也没有涉及

yanzhenjie commented 3 years ago

很好理解呢,每个website就是一个目录,你在电脑中怎么访问多个路径,这里就怎么访问多个路径,跳出框架来看这个点就明白了。

dongweiq commented 1 year ago

其实是想在这里写一个文件浏览的路径和一个网页的路径,让他们配置不同的端口 ,比如文件的是http://127.0.0.1:8888/files/,而网页的是http://127.0.0.1/web/这种,该如何配置呢

很好理解呢,每个website就是一个目录,你在电脑中怎么访问多个路径,这里就怎么访问多个路径,跳出框架来看这个点就明白了。 目的就是想启用多个website,在不同的端口号就行,要怎样配置?

Sogrey commented 10 months ago
@Config
class AppConfig : WebConfig {
    override fun onConfig(context: Context, delegate: WebConfig.Delegate) {
        // 增加一个位于assets的web目录的网站
        delegate.addWebsite(AssetsWebsite(context, "/web/"))
        // 增加一个位于/sdcard/Download/AndServer/目录的网站
        var rootPath = context.getExternalFilesDir(null)?.absolutePath // /sdcard/Android/data/{apppackage}/files/
        delegate.addWebsite(StorageWebsite(rootPath!!, "/test/"))

        // 自定义配置表单请求和文件上传的条件
        delegate.setMultipart(
            Multipart.newBuilder()
                .allFileMaxSize((1024 * 1024 * 20).toLong()) // 单个请求上传文件总大小
                .fileMaxSize((1024 * 1024 * 5).toLong()) // 单个文件的最大大小
                .maxInMemorySize(1024 * 10) // 保存上传文件时buffer大小
                .uploadTempDir(File(context.cacheDir, "_server_upload_cache_")) // 文件保存目录
                .build()
        )

    }
}

我是这样配置,默认访问 为第一个配置。 http://127.0.0.1:8080/index.html -> {appMoudle}/assets/web/html http://127.0.0.1:8080/test/test.apk -> /sdcard/Android/data/{apppackage}/files/test/test.apk