Site: https://main--blog-rest.netlify.app/blog
I am trying to copy over some static resources, and then return an array of available files for a basic express REST api for a blog site. The initial copy is successful, and I verified that the directories exist within dist/
by downloading the zipped deployed files:
I am using a simple script within the package.json to copy these files:
"scripts": {
"build": "npm run clean && npx tsc && npm run copy-blog",
"clean": "rm -rf ./dist",
"copy-blog": "cp -vr ./v1/blog/ ./dist/"
...
And I get the verbose response during build that they were copied successfully:
1:12:04 PM: $ npm run build
1:12:04 PM: > blog-rest@1.0.0 build
1:12:04 PM: > npm run clean && npx tsc && npm run copy-blog
1:12:05 PM: > blog-rest@1.0.0 clean
1:12:05 PM: > rm -rf ./dist
1:12:06 PM: > blog-rest@1.0.0 copy-blog
1:12:06 PM: > cp -vr ./v1/blog/ ./dist/
1:12:06 PM: './v1/blog/' -> './dist/blog'
1:12:06 PM: './v1/blog/first-blog-post.md' -> './dist/blog/first-blog-post.md'
1:12:06 PM: './v1/blog/rendered' -> './dist/blog/rendered'
1:12:06 PM: './v1/blog/rendered/first-blog-post.html' -> './dist/blog/rendered/first-blog-post.html'
However, when I try to access the files within the express route:
router.get("/", async (req: Request, res: Response) => {
try {
const dirPath = "./dist/blog";
const files = await readdir(dirPath);
...
I get the following response:
{"status":500,"errors":[{"errno":-2,"code":"ENOENT","syscall":"scandir","path":"./dist/blog"}],"data":{"message":"ENOENT: no such file or directory, scandir './dist/blog'"}}
This is not a problem locally when I build and run netlify dev
or netlify dev --context production
. I just get the expected response:
{"status":200,"errors":[],"data":["first-blog-post.md"]}
I also messed around with just displaying the contents of the dist directory for a couple deploys and verified that app.js, routes, etc. were all present and I was in the correct directory. But at this point I have no idea why I cannot find the blog directory. Any assistance is appreciated.