MCPcopy Index your code
hub / github.com/11ty/dev-server / getOutputDirFilePath

Method getOutputDirFilePath

server.js:219–252  ·  view source on GitHub ↗
(filepath, filename = "")

Source from the content-addressed store, hash-verified

217 }
218
219 getOutputDirFilePath(filepath, filename = "") {
220 let computedPath;
221 if(filename === ".html") {
222 // avoid trailing slash for filepath/.html requests
223 let prefix = path.join(this.dir, filepath);
224 if(prefix.endsWith(path.sep)) {
225 prefix = prefix.substring(0, prefix.length - path.sep.length);
226 }
227 computedPath = prefix + filename;
228 } else {
229 computedPath = path.join(this.dir, filepath, filename);
230 }
231
232 computedPath = decodeURIComponent(computedPath);
233
234 if(!filename) { // is a direct URL request (not an implicit .html or index.html add)
235 let alias = this.matchPassthroughAlias(filepath);
236
237 if(alias) {
238 if(!this.isFileInDirectory(path.resolve("."), alias)) {
239 throw new Error("Invalid path");
240 }
241
242 return alias;
243 }
244 }
245
246 // Check that the file is in the output path (error if folks try use `..` in the filepath)
247 if(!this.isFileInDirectory(this.dir, computedPath)) {
248 throw new Error("Invalid path");
249 }
250
251 return computedPath;
252 }
253
254 isOutputFilePathExists(rawPath) {
255 return fs.existsSync(rawPath) && !TemplatePath.isDirectorySync(rawPath);

Callers 2

mapUrlToFilePathMethod · 0.95

Calls 2

matchPassthroughAliasMethod · 0.95
isFileInDirectoryMethod · 0.95

Tested by

no test coverage detected