Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redirect not found can be false when syncMode='none' #428

Merged
merged 3 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/port/controller/AbstractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ export abstract class AbstractController extends MiddlewareController {
if (!this.isPrivateScope(scope)) {
// syncMode = none, redirect public package to source registry
if (!this.enableSync) {
err.redirectToSourceRegistry = this.sourceRegistry;
// syncMode = all/exist
if (this.redirectNotFound) {
err.redirectToSourceRegistry = this.sourceRegistry;
}
} else {
// syncMode = all/exist
if (allowSync && this.syncNotFound) {
// ErrorHandler will use syncPackage to create sync task
err.syncPackage = {
Expand Down
2 changes: 1 addition & 1 deletion config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default (appInfo: EggAppConfig) => {
enableNpmClientAndVersionCheck: true,
// sync when package not found, only effect when syncMode = all/exist
syncNotFound: false,
// redirect to source registry when package not found, only effect when syncMode = all/exist
// redirect to source registry when package not found
redirectNotFound: true,
};

Expand Down
9 changes: 9 additions & 0 deletions test/port/controller/package/ShowPackageController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,15 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => {
assert(res.headers.location === 'https://registry.npmjs.org/@eggjs/tegg-metadata?t=0123123&foo=bar');
});

it('should not redirect to source registry when redirectNotFound is false and sync mode is none', async () => {
mock(app.config.cnpmcore, 'syncMode', 'none');
mock(app.config.cnpmcore, 'redirectNotFound', false);
const res = await app.httpRequest()
.get('/@eggjs/tegg-metadata')
.set('Accept', 'application/vnd.npm.install-v1+json');
assert(res.status === 404);
});

it('should redirect public non-scope package to source registry if package not exists when syncMode=none', async () => {
mock(app.config.cnpmcore, 'syncMode', 'none');
let res = await app.httpRequest()
Expand Down