@aeriajs/server 0.0.273 → 0.0.274

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,12 @@ export declare const DEFAULT_API_CONFIG: {
3
3
  defaultPaginationLimit: number;
4
4
  server: {
5
5
  port: number;
6
+ cors: {
7
+ allowOrigin: string[];
8
+ allowMethods: string[];
9
+ allowHeaders: string[];
10
+ maxAge: string;
11
+ };
6
12
  };
7
13
  security: {
8
14
  tokenExpiration: number;
package/dist/constants.js CHANGED
@@ -6,6 +6,22 @@ exports.DEFAULT_API_CONFIG = {
6
6
  defaultPaginationLimit: 10,
7
7
  server: {
8
8
  port: 3000,
9
+ cors: {
10
+ allowOrigin: ['*'],
11
+ allowMethods: ['*'],
12
+ allowHeaders: [
13
+ 'Accept',
14
+ 'Accept-Version',
15
+ 'Authorization',
16
+ 'Content-Length',
17
+ 'Content-MD5',
18
+ 'Content-Type',
19
+ 'Date',
20
+ 'X-Api-Version',
21
+ 'X-Stream-Request',
22
+ ],
23
+ maxAge: '2592000',
24
+ },
9
25
  },
10
26
  security: {
11
27
  tokenExpiration: 36000,
@@ -3,7 +3,23 @@ export const DEFAULT_API_CONFIG = {
3
3
  baseUrl: "/",
4
4
  defaultPaginationLimit: 10,
5
5
  server: {
6
- port: 3e3
6
+ port: 3e3,
7
+ cors: {
8
+ allowOrigin: ["*"],
9
+ allowMethods: ["*"],
10
+ allowHeaders: [
11
+ "Accept",
12
+ "Accept-Version",
13
+ "Authorization",
14
+ "Content-Length",
15
+ "Content-MD5",
16
+ "Content-Type",
17
+ "Date",
18
+ "X-Api-Version",
19
+ "X-Stream-Request"
20
+ ],
21
+ maxAge: "2592000"
22
+ }
7
23
  },
8
24
  security: {
9
25
  tokenExpiration: 36e3,
package/dist/init.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { RouteContext, Collection, GenericRequest, ApiConfig, AuthenticatedToken, NonCircularJsonSchema } from '@aeriajs/types';
2
2
  import { type createRouter } from '@aeriajs/http';
3
3
  import { DEFAULT_API_CONFIG } from './constants.js';
4
- type DeepPartial<T> = T extends object ? {
4
+ type DeepPartial<T> = T extends Record<string, unknown> ? {
5
5
  [P in keyof T]?: DeepPartial<T[P]>;
6
6
  } : T;
7
7
  export type InitApiConfig = Omit<ApiConfig, keyof typeof DEFAULT_API_CONFIG> & DeepPartial<Pick<ApiConfig, keyof typeof DEFAULT_API_CONFIG>>;
package/dist/init.js CHANGED
@@ -67,26 +67,28 @@ const init = (_options = {}) => {
67
67
  const options = Object.assign({
68
68
  config: {},
69
69
  }, _options);
70
- Object.assign(options.config, (0, common_1.deepMerge)(constants_js_1.DEFAULT_API_CONFIG, options.config));
70
+ const config = Object.assign(options.config, (0, common_1.deepMerge)(constants_js_1.DEFAULT_API_CONFIG, options.config));
71
71
  return {
72
72
  options,
73
73
  listen: async () => {
74
- if (!options.config.server) {
74
+ if (!config.server) {
75
75
  throw new Error;
76
76
  }
77
77
  const parentContext = await (0, core_1.createContext)({
78
- config: options.config,
78
+ config,
79
79
  });
80
80
  if (options.setup) {
81
81
  await options.setup(parentContext);
82
82
  }
83
- if (!options.config.server.noWarmup) {
83
+ if (!config.server.noWarmup) {
84
84
  await (0, warmup_js_1.warmup)();
85
85
  }
86
86
  const apiRouter = (0, routes_js_1.registerRoutes)();
87
- const server = (0, node_http_1.registerServer)(options.config.server, async (request, response) => {
88
- if ((0, http_1.cors)(request, response) === null) {
89
- return;
87
+ const server = (0, node_http_1.registerServer)(config.server, async (request, response) => {
88
+ if (config.server && config.server.cors) {
89
+ if ((0, http_1.cors)(request, response, config.server.cors) === null) {
90
+ return;
91
+ }
90
92
  }
91
93
  await (0, http_1.wrapRouteExecution)(response, async () => {
92
94
  const { error, result: token } = await (0, exports.getToken)(request, parentContext);
@@ -114,7 +116,7 @@ const init = (_options = {}) => {
114
116
  return apiRouter.handle(request, response, context);
115
117
  });
116
118
  });
117
- if (!options.config.database?.noDatabase) {
119
+ if (!config.database?.noDatabase) {
118
120
  await (0, core_1.getDatabase)();
119
121
  }
120
122
  server.listen();
package/dist/init.mjs CHANGED
@@ -61,26 +61,28 @@ export const init = (_options = {}) => {
61
61
  const options = Object.assign({
62
62
  config: {}
63
63
  }, _options);
64
- Object.assign(options.config, deepMerge(DEFAULT_API_CONFIG, options.config));
64
+ const config = Object.assign(options.config, deepMerge(DEFAULT_API_CONFIG, options.config));
65
65
  return {
66
66
  options,
67
67
  listen: async () => {
68
- if (!options.config.server) {
68
+ if (!config.server) {
69
69
  throw new Error();
70
70
  }
71
71
  const parentContext = await createContext({
72
- config: options.config
72
+ config
73
73
  });
74
74
  if (options.setup) {
75
75
  await options.setup(parentContext);
76
76
  }
77
- if (!options.config.server.noWarmup) {
77
+ if (!config.server.noWarmup) {
78
78
  await warmup();
79
79
  }
80
80
  const apiRouter = registerRoutes();
81
- const server = registerServer(options.config.server, async (request, response) => {
82
- if (cors(request, response) === null) {
83
- return;
81
+ const server = registerServer(config.server, async (request, response) => {
82
+ if (config.server && config.server.cors) {
83
+ if (cors(request, response, config.server.cors) === null) {
84
+ return;
85
+ }
84
86
  }
85
87
  await wrapRouteExecution(response, async () => {
86
88
  const { error, result: token } = await getToken(request, parentContext);
@@ -108,7 +110,7 @@ export const init = (_options = {}) => {
108
110
  return apiRouter.handle(request, response, context);
109
111
  });
110
112
  });
111
- if (!options.config.database?.noDatabase) {
113
+ if (!config.database?.noDatabase) {
112
114
  await getDatabase();
113
115
  }
114
116
  server.listen();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/server",
3
- "version": "0.0.273",
3
+ "version": "0.0.274",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,14 +33,14 @@
33
33
  "mongodb": "^6.17.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@aeriajs/core": "^0.0.271",
37
- "@aeriajs/builtins": "^0.0.271",
38
- "@aeriajs/common": "^0.0.153",
39
- "@aeriajs/entrypoint": "^0.0.159",
40
- "@aeriajs/http": "^0.0.187",
41
- "@aeriajs/node-http": "^0.0.187",
42
- "@aeriajs/server": "^0.0.273",
43
- "@aeriajs/types": "^0.0.131",
36
+ "@aeriajs/core": "^0.0.272",
37
+ "@aeriajs/builtins": "^0.0.272",
38
+ "@aeriajs/common": "^0.0.154",
39
+ "@aeriajs/entrypoint": "^0.0.160",
40
+ "@aeriajs/http": "^0.0.188",
41
+ "@aeriajs/node-http": "^0.0.188",
42
+ "@aeriajs/server": "^0.0.274",
43
+ "@aeriajs/types": "^0.0.132",
44
44
  "mongodb": "^6.17.0"
45
45
  },
46
46
  "scripts": {