| 2909 | }; |
| 2910 | |
| 2911 | renderDirectoryListing( |
| 2912 | _req: http.IncomingMessage, |
| 2913 | res: http.ServerResponse, |
| 2914 | requestPath: string, |
| 2915 | requestId: string |
| 2916 | ): boolean { |
| 2917 | // If the "directory listing" feature is disabled in the |
| 2918 | // Project's settings, then don't render the directory listing |
| 2919 | if (this.projectSettings?.directoryListing === false) { |
| 2920 | return false; |
| 2921 | } |
| 2922 | |
| 2923 | let prefix = requestPath; |
| 2924 | if (prefix.length > 0 && !prefix.endsWith('/')) { |
| 2925 | prefix += '/'; |
| 2926 | } |
| 2927 | |
| 2928 | const dirs: Set<string> = new Set(); |
| 2929 | const files = Array.from(this.buildMatches.keys()) |
| 2930 | .filter(p => { |
| 2931 | const base = basename(p); |
| 2932 | if ( |
| 2933 | base === 'now.json' || |
| 2934 | base === 'vercel.json' || |
| 2935 | base === 'vercel.toml' || |
| 2936 | base === '.nowignore' || |
| 2937 | base === '.vercelignore' || |
| 2938 | !p.startsWith(prefix) |
| 2939 | ) { |
| 2940 | return false; |
| 2941 | } |
| 2942 | const rel = relative(prefix, p); |
| 2943 | if (rel.includes('/')) { |
| 2944 | const dir = rel.split('/')[0]; |
| 2945 | if (dirs.has(dir)) { |
| 2946 | return false; |
| 2947 | } |
| 2948 | dirs.add(dir); |
| 2949 | } |
| 2950 | return true; |
| 2951 | }) |
| 2952 | .map(p => { |
| 2953 | let base = basename(p); |
| 2954 | let ext = ''; |
| 2955 | let type = 'file'; |
| 2956 | let href: string; |
| 2957 | |
| 2958 | const rel = relative(prefix, p); |
| 2959 | if (rel.includes('/')) { |
| 2960 | // Directory |
| 2961 | type = 'folder'; |
| 2962 | base = rel.split('/')[0]; |
| 2963 | href = `/${prefix}${base}/`; |
| 2964 | } else { |
| 2965 | // File / Lambda |
| 2966 | ext = extname(p).substring(1); |
| 2967 | href = `/${prefix}${base}`; |
| 2968 | } |