Skip to content

Commit fc7d94b

Browse files
fix(): update dates, revert http prefix changes
1 parent 7ac42b0 commit fc7d94b

15 files changed

Lines changed: 49 additions & 39 deletions

File tree

packages/common/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Nest @common
3-
* Copyright(c) 2017 - 2019 Kamil Mysliwiec
3+
* Copyright(c) 2017 - 2020 Kamil Mysliwiec
44
* https://nestjs.com
55
* MIT Licensed
66
*/
@@ -18,10 +18,13 @@ export {
1818
BeforeApplicationShutdown,
1919
CallHandler,
2020
CanActivate,
21+
ClassProvider,
2122
ContextType,
2223
DynamicModule,
2324
ExceptionFilter,
2425
ExecutionContext,
26+
ExistingProvider,
27+
FactoryProvider,
2528
ForwardReference,
2629
HttpServer,
2730
INestApplication,
@@ -44,6 +47,7 @@ export {
4447
ScopeOptions,
4548
Type,
4649
ValidationError,
50+
ValueProvider,
4751
WebSocketAdapter,
4852
WsExceptionFilter,
4953
WsMessageHandler,

packages/common/interfaces/http/http-server.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export interface HttpServer<TRequest = any, TResponse = any> {
5959
getRequestMethod?(request: TRequest): string;
6060
getRequestUrl?(request: TResponse): string;
6161
getInstance(): any;
62-
registerParserMiddleware(prefix?: string): any;
63-
enableCors(options: CorsOptions, prefix?: string): any;
62+
registerParserMiddleware(): any;
63+
enableCors(options: CorsOptions): any;
6464
getHttpServer(): any;
6565
initHttpServer(options: NestApplicationOptions): void;
6666
close(): any;

packages/core/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Nest @core
3-
* Copyright(c) 2017 - 2019 Kamil Mysliwiec
3+
* Copyright(c) 2017 - 2020 Kamil Mysliwiec
44
* https://nestjs.com
55
* MIT Licensed
66
*/
@@ -13,6 +13,7 @@ export * from './discovery';
1313
export * from './exceptions';
1414
export * from './helpers';
1515
export * from './injector';
16+
export * from './metadata-scanner';
1617
export * from './middleware';
1718
export * from './nest-application';
1819
export * from './nest-application-context';

packages/core/nest-application.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ export class NestApplication extends NestApplicationContext
140140

141141
const useBodyParser =
142142
this.appOptions && this.appOptions.bodyParser !== false;
143-
useBodyParser &&
144-
this.registerParserMiddleware(this.config.getGlobalPrefix());
143+
useBodyParser && this.registerParserMiddleware();
145144

146145
await this.registerModules();
147146
await this.registerRouter();
@@ -154,8 +153,8 @@ export class NestApplication extends NestApplicationContext
154153
return this;
155154
}
156155

157-
public registerParserMiddleware(prefix = '/') {
158-
this.httpAdapter.registerParserMiddleware(prefix);
156+
public registerParserMiddleware() {
157+
this.httpAdapter.registerParserMiddleware();
159158
}
160159

161160
public async registerRouter() {
@@ -217,7 +216,7 @@ export class NestApplication extends NestApplicationContext
217216
}
218217

219218
public enableCors(options?: CorsOptions): void {
220-
this.httpAdapter.enableCors(options, this.config.getGlobalPrefix());
219+
this.httpAdapter.enableCors(options);
221220
}
222221

223222
public async listen(

packages/core/test/utils/noop-adapter.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class NoopHttpAdapter extends AbstractHttpAdapter {
1919
setErrorHandler(handler: Function, prefix = '/'): any {}
2020
setNotFoundHandler(handler: Function, prefix = '/'): any {}
2121
setHeader(response: any, name: string, value: string): any {}
22-
registerParserMiddleware(prefix = '/'): any {}
23-
enableCors(options: any, prefix = '/'): any {}
22+
registerParserMiddleware(): any {}
23+
enableCors(options: any): any {}
2424
createMiddlewareFactory(requestMethod: RequestMethod): any {}
2525
getType() {
2626
return '';

packages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Nest
3-
* Copyright(c) 2017 - 2019 Kamil Mysliwiec
3+
* Copyright(c) 2017 - 2020 Kamil Mysliwiec
44
* https://nestjs.com
55
* MIT Licensed
66
*/

packages/microservices/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Nest @microservices
3-
* Copyright(c) 2017 - 2019 Kamil Mysliwiec
3+
* Copyright(c) 2017 - 2020 Kamil Mysliwiec
44
* https://nestjs.com
55
* MIT Licensed
66
*/

packages/platform-express/adapters/express-adapter.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ export class ExpressAdapter extends AbstractHttpAdapter {
4040
return response.redirect(statusCode, url);
4141
}
4242

43-
public setErrorHandler(handler: Function, prefix = '/') {
43+
public setErrorHandler(handler: Function, prefix?: string) {
44+
if (prefix) {
45+
return this.use(prefix, handler);
46+
}
4447
return this.use(handler);
4548
}
4649

47-
public setNotFoundHandler(handler: Function, prefix = '/') {
50+
public setNotFoundHandler(handler: Function, prefix?: string) {
51+
if (prefix) {
52+
return this.use(prefix, handler);
53+
}
4854
return this.use(handler);
4955
}
5056

@@ -108,7 +114,7 @@ export class ExpressAdapter extends AbstractHttpAdapter {
108114
return request.url;
109115
}
110116

111-
public enableCors(options: CorsOptions, prefix = '/') {
117+
public enableCors(options: CorsOptions) {
112118
return this.use(cors(options));
113119
}
114120

@@ -132,7 +138,7 @@ export class ExpressAdapter extends AbstractHttpAdapter {
132138
this.httpServer = http.createServer(this.getInstance());
133139
}
134140

135-
public registerParserMiddleware(prefix = '/') {
141+
public registerParserMiddleware() {
136142
const parserMiddleware = {
137143
jsonParser: bodyParser.json(),
138144
urlencodedParser: bodyParser.urlencoded({ extended: true }),

packages/platform-express/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Nest @platform-express
3-
* Copyright(c) 2017 - 2019 Kamil Mysliwiec
3+
* Copyright(c) 2017 - 2020 Kamil Mysliwiec
44
* https://nestjs.com
55
* MIT Licensed
66
*/

packages/platform-fastify/adapters/fastify-adapter.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ export class FastifyAdapter<TInstance = any> extends AbstractHttpAdapter {
6868

6969
public setErrorHandler(
7070
handler: Parameters<fastify.FastifyInstance['setErrorHandler']>[0],
71-
prefix = '/',
71+
prefix?: string,
7272
) {
73+
if (!prefix) {
74+
return this.instance.setErrorHandler(handler);
75+
}
7376
return this.registerWithPrefix(
7477
async (instance: fastify.FastifyInstance): Promise<void> => {
7578
instance.setErrorHandler(handler);
@@ -80,8 +83,11 @@ export class FastifyAdapter<TInstance = any> extends AbstractHttpAdapter {
8083

8184
public setNotFoundHandler(
8285
handler: Parameters<fastify.FastifyInstance['setNotFoundHandler']>[0],
83-
prefix = '/',
86+
prefix?: string,
8487
) {
88+
if (!prefix) {
89+
return this.instance.setNotFoundHandler(handler);
90+
}
8591
return this.registerWithPrefix(
8692
async (instance: fastify.FastifyInstance): Promise<void> => {
8793
instance.setNotFoundHandler(handler);
@@ -152,22 +158,16 @@ export class FastifyAdapter<TInstance = any> extends AbstractHttpAdapter {
152158
return request.raw.url;
153159
}
154160

155-
public enableCors(options: CorsOptions, prefix = '/') {
156-
return this.registerWithPrefix(
157-
async (instance: fastify.FastifyInstance): Promise<void> => {
158-
instance.register(cors, (options as unknown) as {});
159-
},
160-
prefix,
161-
);
161+
public enableCors(options: CorsOptions) {
162+
try {
163+
this.register(cors, options);
164+
} catch {}
162165
}
163166

164-
public registerParserMiddleware(prefix = '/') {
165-
return this.registerWithPrefix(
166-
async (instance: fastify.FastifyInstance): Promise<void> => {
167-
instance.register(formBody);
168-
},
169-
prefix,
170-
);
167+
public registerParserMiddleware() {
168+
try {
169+
this.register(formBody);
170+
} catch {}
171171
}
172172

173173
public createMiddlewareFactory(

0 commit comments

Comments
 (0)