Comments (6)
You should set wildcard
to false
.
https://github.com/fastify/fastify-static#wildcard
from fastify-static.
Hello @mcollina,
It is already set to false
: https://github.com/Yberion/Angular-SSR-Common-Engine/blob/bug/fastify-server/server/fastify/server.ts#L23
Only the root path has this behavior which is problematic and doesn't happen with Express (even with express static https://github.com/Yberion/Angular-SSR-Common-Engine/blob/bug/fastify-server/server/express/server.ts#L21)
from fastify-static.
Note that you need two routes, one for /*
and one for /
(the wildcard does not match /)
from fastify-static.
I tried to declare both routes, but it looks like /
is already declared by the static
plugin which is the main issue and prevent me from adding additional logic to the root path:
server.get('/*', (req, res) => {
const baseURL = req.protocol + '://' + req.headers.host;
const url = new URL(req.url, baseURL);
console.log(baseURL);
console.log(url);
console.log(req.url);
commonEngine.render({
bootstrap: AppServerModule,
documentFilePath: INDEX_HTML,
url: url.href,
providers: [{ provide: APP_BASE_HREF, useValue: baseURL }]
})
.then((r) => res.type('text/html').send(r))
.catch(err => console.error(err));
});
server.get('/', (req, res) => {
const baseURL = req.protocol + '://' + req.headers.host;
const url = new URL(req.url, baseURL);
console.log(baseURL);
console.log(url);
console.log(req.url);
commonEngine.render({
bootstrap: AppServerModule,
documentFilePath: INDEX_HTML,
url: url.href,
providers: [{ provide: APP_BASE_HREF, useValue: baseURL }]
})
.then((r) => res.type('text/html').send(r))
.catch(err => console.error(err));
});
I'm facing this error:
FastifyError [Error]: Method 'GET' already declared for route '/'
at Object.addNewRoute (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:2037596)
at Object.route (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:2035586)
at Object.prepareRoute (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:2034148)
at Object._get [as get] (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:1922279)
at D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:1:18794
at Generator.next (<anonymous>)
at asyncGeneratorStep (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:2114937)
at _next (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:2115240)
at _ZoneDelegate2.invoke (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:1814804)
at Zone3.run (D:\GitHub\Angular-SSR-Common-Engine\dist\Angular-SSR-Common-Engine\server\fastify\main.js:7:1807089) {
code: 'FST_ERR_DUPLICATED_ROUTE',
statusCode: 500
}
from fastify-static.
Seems like the folder you serve have index.html
inside.
You may try index: false
to disable serving index file.
from fastify-static.
Seems like the folder you serve have
index.html
inside. You may tryindex: false
to disable serving index file.
Thanks for your help @climba03003, this was the right setting, server.g('*', ...)
now catch the /
path. 😃
from fastify-static.
Related Issues (20)
- Plugin not supporting Fastify 3.x version HOT 5
- Multi-root + pre-compression causes infinite loop HOT 2
- Not working after update HOT 3
- Forking send to @fastify/send to avoid CVE warning
- setNotFoundHandler and @fastify/static context issue HOT 2
- Parameter in route and serving files HOT 2
- Support URL for root parameter (and `file:` protocol) HOT 9
- Serve the same html for all get routes HOT 1
- Regression on isUtf8MimeType HOT 5
- Investigate path-scurry by @isaacs HOT 2
- Why @[email protected] bind [email protected] rather than 4.x HOT 1
- 我正在使用 nestjs,并通过 fastify-static 使用 public static,但我无法在打包时自动让目录 public 在目录 dist 内生成。 HOT 1
- . HOT 1
- inflight - transient dependency introduced memory leak HOT 8
- Correct module exports? HOT 2
- abstract the plugin to provide support of virtual file system HOT 1
- `FST_ERR_REP_ALREADY_SENT` when wrapping route handler HOT 5
- 404 when using wildcard HOT 3
- setting content-length HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-static.