Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eriksson-daniel committed Nov 11, 2024
1 parent 769a530 commit cf2b5fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"type": "module",
"scripts": {
"start": "vite --base=/ & tsc --watch",
"build": "vite build",
"build:local": "vite --base=/ build",
"build": "vite build && bun run copy:robots",
"build:local": "vite --base=/ build && bun run copy:robots",
"copy:robots": "cp assets/robots.txt dist/assets/robots.txt",
"typecheck": "tsc",
"lint": "biome check"
},
Expand Down Expand Up @@ -41,4 +42,4 @@
"react-router-dom": "6.28.0",
"styled-components": "6.1.13"
}
}
}
11 changes: 7 additions & 4 deletions server/src/plugins/not-found.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ const log = getLogger('not-found-plugin');

export const NOT_FOUND_PLUGIN_ID = 'not-found';

const HARMLESS_NOT_FOUND_PATHS = ['/favicon.ico', '/'];

export const notFoundPlugin = fastifyPlugin(
async (app) => {
app.setNotFoundHandler((req, reply) => {
if (isDeployedToProd) {
log.warn({
// if (isDeployedToProd) {
const harmless = HARMLESS_NOT_FOUND_PATHS.includes(req.url)
log[harmless ? "debug" : 'warn']({
msg: `Invalid URL. Redirecting to external URL ${YTELSE_OVERVIEW_URL}`,
data: { url: req.url },
});
Expand All @@ -25,9 +28,9 @@ export const notFoundPlugin = fastifyPlugin(
});

return reply.redirect(YTELSE_OVERVIEW_URL);
}
// }

return reply.status(404).header('content-type', 'text/html').send(DEV_404_HTML);
// return reply.status(404).header('content-type', 'text/html').send(DEV_404_HTML);
});
},
{ fastify: '5', name: NOT_FOUND_PLUGIN_ID, dependencies: [SERVE_INDEX_PLUGIN_ID] },
Expand Down
12 changes: 12 additions & 0 deletions server/src/plugins/serve-robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fastifyPlugin from 'fastify-plugin';

export const SERVE_ROBOTS_PLUGIN_ID = 'serve-robots';

export const serveRobotsPlugin = fastifyPlugin(
async (app) => {
app.get('/robots.txt', async (_, res) => {
res.redirect('https://cdn.nav.no/klage/klang/assets/robots.txt');
})
},
{ fastify: '5', name: SERVE_ROBOTS_PLUGIN_ID},
);
2 changes: 2 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { EmojiIcons, sendToSlack } from '@app/slack';
import cors from '@fastify/cors';
import { fastify } from 'fastify';
import metricsPlugin from 'fastify-metrics';
import { serveRobotsPlugin } from './plugins/serve-robots';

processErrors();

Expand Down Expand Up @@ -52,6 +53,7 @@ fastify({ trustProxy: true, querystringParser, bodyLimit, caseSensitive: false }
.register(frontendLogPlugin)
.register(errorReportPlugin)
.register(accessTokenPlugin)
.register(serveRobotsPlugin)
.register(oboAccessTokenPlugin)
.register(apiProxyPlugin, { appNames: API_CLIENT_IDS, prefix: '/api' })
.register(localDevPlugin)
Expand Down

0 comments on commit cf2b5fa

Please sign in to comment.