mielk-api 1.2.0 → 1.2.2
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.
- package/dist/db/pg/connection/pool.js +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/express.js +2 -1
- package/dist/http/apiResponse/apiResponse.js +1 -1
- package/dist/internal/messaging/messageTags.js +9 -9
- package/dist/middlewares/cors/cors.js +1 -1
- package/dist/middlewares/requestAuth/auth.middleware.js +5 -2
- package/dist/routing/controllers/health.controller.js +1 -1
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@ export function getPool() {
|
|
|
22
22
|
return pool;
|
|
23
23
|
if (config === null)
|
|
24
24
|
throw new Error(Msg.connection.notInitialized);
|
|
25
|
-
if (!isProd) {
|
|
25
|
+
if (!isProd()) {
|
|
26
26
|
if (!config.ssh)
|
|
27
27
|
throw new Error(Msg.connection.sshOptionsNotSpecified);
|
|
28
28
|
const port = yield openSshTunnel(config.ssh, config.port);
|
package/dist/express.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { DbConfig } from './db/pg/index.js';
|
|
2
2
|
import { CorsConfig, RateLimitConfig } from './middlewares/index.js';
|
|
3
3
|
export declare const createExpressApp: (isProd: boolean, dbConfig: DbConfig, corsConfig: CorsConfig, rateLimitConfig?: RateLimitConfig) => import("express-serve-static-core").Express;
|
|
4
|
-
export declare const isProd: boolean;
|
|
4
|
+
export declare const isProd: () => boolean;
|
package/dist/express.js
CHANGED
|
@@ -7,10 +7,11 @@ const env = {
|
|
|
7
7
|
export const createExpressApp = (isProd, dbConfig, corsConfig, rateLimitConfig) => {
|
|
8
8
|
const app = express();
|
|
9
9
|
env.isProd = isProd;
|
|
10
|
+
console.log();
|
|
10
11
|
initDb(dbConfig);
|
|
11
12
|
initCors(corsConfig);
|
|
12
13
|
setRateLimit(app, rateLimitConfig);
|
|
13
14
|
app.use(express.json());
|
|
14
15
|
return app;
|
|
15
16
|
};
|
|
16
|
-
export const isProd = env.isProd;
|
|
17
|
+
export const isProd = () => env.isProd;
|
|
@@ -22,7 +22,7 @@ export function serverError(res, err) {
|
|
|
22
22
|
const status = HttpResponseStatus.SERVER_ERROR;
|
|
23
23
|
const apiError = {
|
|
24
24
|
success: false,
|
|
25
|
-
message: isProd ? status.defaultMessageTag : `message: ${err.message} | stack: ${(_a = err.stack) === null || _a === void 0 ? void 0 : _a.toString()}`,
|
|
25
|
+
message: isProd() ? status.defaultMessageTag : `message: ${err.message} | stack: ${(_a = err.stack) === null || _a === void 0 ? void 0 : _a.toString()}`,
|
|
26
26
|
};
|
|
27
27
|
res.status(status.code).json(apiError);
|
|
28
28
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const PARENT_FOLDER = 'api/';
|
|
2
|
-
const
|
|
3
|
-
const ___CONNECTION___ = `${PARENT_FOLDER}/
|
|
2
|
+
const ___HTTP_STATUS___ = `${PARENT_FOLDER}/httpStatus`;
|
|
3
|
+
const ___CONNECTION___ = `${PARENT_FOLDER}/connection`;
|
|
4
4
|
export const Msg = {
|
|
5
5
|
apiStatus: {
|
|
6
|
-
ok: `${
|
|
7
|
-
created: `${
|
|
8
|
-
unauthorized: `${
|
|
9
|
-
badRequest: `${
|
|
10
|
-
notFound: `${
|
|
11
|
-
conflict: `${
|
|
12
|
-
serverError: `${
|
|
6
|
+
ok: `${___HTTP_STATUS___}:ok`,
|
|
7
|
+
created: `${___HTTP_STATUS___}:created`,
|
|
8
|
+
unauthorized: `${___HTTP_STATUS___}:unauthorized`,
|
|
9
|
+
badRequest: `${___HTTP_STATUS___}:badRequest`,
|
|
10
|
+
notFound: `${___HTTP_STATUS___}:notFound`,
|
|
11
|
+
conflict: `${___HTTP_STATUS___}:conflict`,
|
|
12
|
+
serverError: `${___HTTP_STATUS___}:serverError`,
|
|
13
13
|
},
|
|
14
14
|
connection: {
|
|
15
15
|
corsBlocked: `${___CONNECTION___}:corsBlocked`,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { HttpResponseStatus } from '../../http/httpResponseStatus/HttpResponseStatus.js';
|
|
2
|
+
import { Msg } from '../../internal/messaging/messageTags.js';
|
|
1
3
|
import { isProd } from '../../express.js';
|
|
4
|
+
import { failure } from '../../http/index.js';
|
|
2
5
|
import { apiKey } from '../cors/cors.js';
|
|
3
6
|
export function apiKeyAuthorization(req, res, next) {
|
|
4
7
|
var _a;
|
|
5
|
-
if (!isProd) {
|
|
8
|
+
if (!isProd()) {
|
|
6
9
|
return next();
|
|
7
10
|
}
|
|
8
11
|
const key = (_a = req.headers['authorization']) === null || _a === void 0 ? void 0 : _a.split(' ')[1]; // Bearer <key>
|
|
9
12
|
if (!apiKey && (!key || key !== apiKey)) {
|
|
10
|
-
|
|
13
|
+
failure(res, HttpResponseStatus.UNAUTHORIZED, Msg.connection.unauthorizedRequest);
|
|
11
14
|
}
|
|
12
15
|
next();
|
|
13
16
|
}
|