Merge pull request #27081 from backstage/rugvip/pretty

backend-defaults: pretty-print JSON responses during development
This commit is contained in:
Patrik Oldsberg
2024-10-11 13:21:28 +02:00
committed by GitHub
3 changed files with 24 additions and 1 deletions
@@ -59,7 +59,7 @@ const backend = createBackend();
backend.add(
rootHttpRouterServiceFactory({
configure: ({ app, middleware, routes, config, logger, lifecycle }) => {
configure: ({ app, middleware, routes, config, logger, healthRouter }) => {
// Refer to https://expressjs.com/en/guide/writing-middleware.html on how to write express middleware
const customMiddleware = {
logging(): RequestHandler {
@@ -88,11 +88,18 @@ backend.add(
},
};
// The default implementation pretty-prints JSON responses in development
if (process.env.NODE_ENV === 'development') {
app.set('json spaces', 2);
}
// the built in middleware is provided through an option in the configure function
app.use(middleware.helmet());
app.use(middleware.cors());
app.use(middleware.compression());
app.use(healthRouter);
// you can add you your own middleware in here
app.use(customMiddleware.logging());