Skip to content

Commit

Permalink
fix: handle async chunks properly
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Aug 4, 2022
1 parent 7534549 commit 13111d6
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 484 deletions.
2 changes: 1 addition & 1 deletion examples/with-fastify-auth/cookieAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports.cookieAuth = function cookieAuth(fastify, { queue }, next) {
fastify.route({
method: 'GET',
url: '/cookie/login',
handler: async (req, reply) => {
handler: (req, reply) => {
reply.view('login.ejs');
},
});
Expand Down
11 changes: 6 additions & 5 deletions examples/with-fastify-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"author": "felixmosh",
"license": "ISC",
"dependencies": {
"@bull-board/fastify": "^3.10.7",
"@fastify/basic-auth": "^3.0.1",
"@fastify/cookie": "^6.0.0",
"@fastify/jwt": "^5.0.1",
"@bull-board/fastify": "^4.2.1",
"@fastify/basic-auth": "^4.0.0",
"@fastify/cookie": "^7.3.1",
"@fastify/jwt": "^6.3.2",
"@fastify/view": "^7.0.0",
"bullmq": "^1.81.1",
"fastify": "^3.29.0"
"fastify": "^4.3.0"
},
"devDependencies": {
"nodemon": "^2.0.16"
Expand Down
596 changes: 291 additions & 305 deletions examples/with-fastify-auth/yarn.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/with-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"author": "felixmosh",
"license": "ISC",
"dependencies": {
"@bull-board/fastify": "^3.10.7",
"@bull-board/fastify": "^4.2.1",
"bullmq": "^1.81.1",
"fastify": "^3.29.0"
"fastify": "^4.3.0"
}
}
334 changes: 179 additions & 155 deletions examples/with-fastify/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/with-multiple-instances/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "felixmosh",
"license": "ISC",
"dependencies": {
"@bull-board/express": "^3.0.0",
"@bull-board/express": "^4.2.1",
"body-parser": "^1.20.0",
"bullmq": "^1.80.4",
"express": "^4.17.3"
Expand Down
8 changes: 5 additions & 3 deletions packages/express/src/ExpressAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import express, { Express, NextFunction, Request, Response, Router } from 'express';
import ejs from 'ejs';
import {
AppControllerRoute,
AppViewRoute,
Expand All @@ -8,6 +6,8 @@ import {
HTTPMethod,
IServerAdapter,
} from '@bull-board/api/dist/typings/app';
import ejs from 'ejs';
import express, { Express, NextFunction, Request, Response, Router } from 'express';
import { wrapAsync } from './helpers/wrapAsync';

export class ExpressAdapter implements IServerAdapter {
Expand Down Expand Up @@ -87,7 +87,9 @@ export class ExpressAdapter implements IServerAdapter {
const { name } = routeDef.handler();

const viewHandler = (_req: Request, res: Response) => {
res.render(name, { basePath: this.basePath });
const basePath = this.basePath.endsWith('/') ? this.basePath : `${this.basePath}/`;

res.render(name, { basePath });
};

this.app[routeDef.method](routeDef.route, viewHandler);
Expand Down
9 changes: 4 additions & 5 deletions packages/fastify/src/FastifyAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from '@bull-board/api/dist/typings/app';

import fastifyStatic from '@fastify/static';
import pointOfView from '@fastify/view';
import { FastifyInstance } from 'fastify';
import { HTTPMethods } from 'fastify/types/utils';
import pointOfView from '@fastify/view';

type FastifyRouteDef = {
method: HTTPMethods;
Expand Down Expand Up @@ -116,9 +116,9 @@ export class FastifyAdapter implements IServerAdapter {
method,
url,
handler: (_req, reply) => {
reply.view(filename, {
basePath: this.basePath,
});
const basePath = this.basePath.endsWith('/') ? this.basePath : `${this.basePath}/`;

reply.view(filename, { basePath });
},
})
);
Expand Down Expand Up @@ -150,4 +150,3 @@ export class FastifyAdapter implements IServerAdapter {
};
}
}

3 changes: 2 additions & 1 deletion packages/hapi/src/HapiAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export class HapiAdapter implements IServerAdapter {
options,
handler: (_request, h) => {
const { name } = handler();
return h.view(name, { basePath: this.basePath });
const basePath = this.basePath.endsWith('/') ? this.basePath : `${this.basePath}/`;
return h.view(name, { basePath });
},
})
);
Expand Down
3 changes: 2 additions & 1 deletion packages/koa/src/KoaAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export class KoaAdapter implements IServerAdapter {
viewRoutes.forEach((path) => {
router[method](path, async (ctx) => {
const { name } = handler();
await (ctx as any).render(name, { basePath: this.basePath });
const basePath = this.basePath.endsWith('/') ? this.basePath : `${this.basePath}/`;
await (ctx as any).render(name, { basePath });
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<meta name="robots" content="noindex" />
<base href="<%= basePath %>" />
<title>Bull Dashboard</title>
<link rel="alternate icon" type="image/png" href="<%= basePath %>/static/favicon-32x32.png">
<link rel="icon" type="image/svg+xml" id="fav-logo" href="<%= basePath %>/static/images/logo.svg">
<link rel="alternate icon" type="image/png" href="static/favicon-32x32.png">
<link rel="icon" type="image/svg+xml" id="fav-logo" href="static/images/logo.svg">
<link href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500&display=swap" rel="stylesheet">
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/services/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class Api {
private axios: AxiosInstance;

constructor({ basePath }: { basePath: string } = { basePath: '' }) {
this.axios = Axios.create({ baseURL: `${basePath}/api` });
this.axios = Axios.create({ baseURL: `${basePath}api` });
this.axios.interceptors.response.use(this.handleResponse, this.handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/utils/getStaticPath.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function getStaticPath(path: string): string {
return `${(window as any).__basePath__}/static${path}`;
return `static${path}`;
}
4 changes: 3 additions & 1 deletion packages/ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = {
output: {
path: path.resolve(__dirname, './dist/static'),
filename: `[name]${isProd ? '.[contenthash]' : ''}.js`,
publicPath: `${isProd ? basePath : `http://localhost:${devServerPort}`}/static/`,
publicPath: `${!isProd ? `http://localhost:${devServerPort}/` : 'static/'}`,
chunkFilename: '[contenthash].chunk.js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
Expand Down Expand Up @@ -88,6 +89,7 @@ module.exports = {
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[contenthash].chunk.css',
}),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, './dist/index.ejs'),
Expand Down

0 comments on commit 13111d6

Please sign in to comment.