A case of Typescript files inside Pages - Returning a Response from an endpoint is not supported in SSG mode in build mode
What version of astro are you using?
^1.2.7
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
yarn
What operating system are you using?
Mac
Describe the Bug
Hi, first of all thanks for this amazing tool!
My problem is with File Routes. There's a contraint that makes impossible to keep a folder structure like this:
src/
└── pages/
└── home/
├── components/
│ └── hello-world/
│ └── index.ts
├── services/
│ └── lead.ts
├── entities/
├── use-cases/
└── utils/
For vanilla projects we can't use javascript/typescript files inside pages directory, it generates an error on build process:
Returning a Response from an endpoint is not supported in SSG mode.
I believe that proposed folder structure helps in scalability matter, when we have to differentiate what's common and what's specific inside the project that can get very big.
It seems that there's a glob looking for every .ts/.js file inside pages and it seems to be very general behavior which can break easily in a project that needs to slightly change the folder structure standard.
It's kind of an inconsistent behavior, because I only figure out that it wasn't possible to do after I run build, it turns out it works really well on development mode...
Suggestion
What if we were able to bypass that behavior by defining a glob pattern to match only the files we want to resolve Files Routes? E.g
defineConfig({
filesRoutes: "/pages/**/static-*.{ts,js}"
})
I don't know... maybe it helps to keep Astro less fragile on this subject...
Thank you in advance!
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-8qxz76?file=src/pages/index.astro
Participation
- [ ] I am willing to submit a pull request for this issue.