www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Vibe D: Get access to files

reply Alexander Zhirov <azhirov1991 gmail.com> writes:
Is there a universal way to access files (styles, scripts) for 
nested paths?


```
string datapath = "./";
auto router = new URLRouter;
router.get("/", &getReq);
router.get("*", serveStaticFiles(buildPath(datapath, "public")));
router.get("*", serveStaticFiles(buildPath(datapath, "images")));
router.get("*", serveStaticFiles(buildPath(datapath, "js")));
auto profile = new URLRouter("/profile");
profile.get("/", &getReqProfile);
profile.get("/test", &getReqProfile);
profile.get("*", serveStaticFiles(buildPath(datapath, "public")));
profile.get("*", serveStaticFiles(buildPath(datapath, "images")));
profile.get("*", serveStaticFiles(buildPath(datapath, "js")));
router.any("*", profile);

// / -> OK
// /profile -> 404
// /profile/ -> OK without css, js
// /profile/test -> OK without css, js
```

![img](https://private-user-images.githubusercontent.com/37277056/303528758-0e0d1e69-09c1-4a91-aaa5-91a10b5e119b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDc0OTk3MjAsIm5iZiI6MTcwNzQ5OTQyMCwicGF0aCI6Ii8zNzI3NzA1Ni8zMDM1Mjg3NTgtMGUwZDFlNjktMDljMS00YTkxLWFhYTUtOTFhMTBiNWUxMTliLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwMjA5VDE3MjM0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQzMTU2ZDUxOGU1OTMyY2JkMGUwYTcyOTcyZjk2ZTY3MmY2YTc2N2ZmMTRkMTk1ZjA4N2QzNGJkNzkxNjU4OTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.LYCDrhyUkPV5EIxCR64N7iDNQFpxHvqMi62BoAJdglQ)

Page 404 also does not load styles if the path is similar to 
`/abc/asd/asd`, but if the path is single-level, then the styles 
are loaded.
Feb 09
parent Alexander Zhirov <azhirov1991 gmail.com> writes:
In the files, dt specified the path to the files from the root 
`/style.css` and now, with any path from the root, files are 
loaded into the page, instead of `style.css`. My mistake.
Feb 09