Skip to content

Commit 9462df7

Browse files
committed
feat: 404 wp-includes
1 parent dc8363e commit 9462df7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/server/src/appInsightsPlugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ export const appInsightsPlugin = fp(async (fastify: FastifyInstance, options: Fa
1616
}
1717

1818
const client: appInsights.TelemetryClient = options.client;
19+
const urlsToIgnore = options.urlsToIgnore || [];
1920

2021
fastify.addHook('onRequest', async (request, _reply) => {
2122
const start = Date.now();
2223
request.app = { start };
2324
});
2425

2526
fastify.addHook('onResponse', async (request, reply) => {
26-
if (request.raw.url === '/') return; // Ignore health check
27+
if (urlsToIgnore.includes(request.raw.url)) return;
2728

2829
const duration = Date.now() - request.app.start;
2930
client.trackRequest({

src/server/src/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const fastify: FastifyInstance = Fastify({
2828
logger: true,
2929
});
3030

31-
fastify.register(appInsightsPlugin, { client });
31+
fastify.register(appInsightsPlugin, { client, urlsToIgnore: ['/'] });
3232

3333
fastify.register(helmet, {
3434
contentSecurityPolicy: {
@@ -40,6 +40,12 @@ fastify.register(helmet, {
4040
},
4141
});
4242

43+
fastify.addHook('onRequest', async (request, reply) => {
44+
if (request.url.includes('wp-includes') || request.url.includes('wp-admin')) {
45+
reply.code(404).send('Not Found');
46+
}
47+
});
48+
4349
routes(fastify);
4450

4551
const __filename = fileURLToPath(import.meta.url);

0 commit comments

Comments
 (0)