@gustavo-valsechi/node 1.0.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/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +171 -0
- package/dist/index.mjs +129 -0
- package/dist/src/database/index.d.mts +5 -0
- package/dist/src/database/index.d.ts +5 -0
- package/dist/src/database/index.js +62 -0
- package/dist/src/database/index.mjs +37 -0
- package/dist/src/router/index.d.mts +9 -0
- package/dist/src/router/index.d.ts +9 -0
- package/dist/src/router/index.js +92 -0
- package/dist/src/router/index.mjs +54 -0
- package/dist/src/server/index.d.mts +8 -0
- package/dist/src/server/index.d.ts +8 -0
- package/dist/src/server/index.js +119 -0
- package/dist/src/server/index.mjs +83 -0
- package/dist/src/tools/index.d.mts +5 -0
- package/dist/src/tools/index.d.ts +5 -0
- package/dist/src/tools/index.js +44 -0
- package/dist/src/tools/index.mjs +17 -0
- package/package.json +70 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { databaseInit } from './src/database/index.mjs';
|
|
2
|
+
export { apiRouter, mainRouter } from './src/router/index.mjs';
|
|
3
|
+
export { app, serverInit } from './src/server/index.mjs';
|
|
4
|
+
export { responseWrapper } from './src/tools/index.mjs';
|
|
5
|
+
import 'typeorm';
|
|
6
|
+
import 'fastify';
|
|
7
|
+
import 'http';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { databaseInit } from './src/database/index.js';
|
|
2
|
+
export { apiRouter, mainRouter } from './src/router/index.js';
|
|
3
|
+
export { app, serverInit } from './src/server/index.js';
|
|
4
|
+
export { responseWrapper } from './src/tools/index.js';
|
|
5
|
+
import 'typeorm';
|
|
6
|
+
import 'fastify';
|
|
7
|
+
import 'http';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
apiRouter: () => apiRouter,
|
|
34
|
+
app: () => app,
|
|
35
|
+
databaseInit: () => databaseInit,
|
|
36
|
+
mainRouter: () => mainRouter,
|
|
37
|
+
responseWrapper: () => responseWrapper,
|
|
38
|
+
serverInit: () => serverInit
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
|
|
42
|
+
// src/database/index.ts
|
|
43
|
+
var import_config = require("dotenv/config");
|
|
44
|
+
var import_os = require("os");
|
|
45
|
+
var import_typeorm = require("typeorm");
|
|
46
|
+
var databaseInit = (options) => {
|
|
47
|
+
const type = process.env.DB_TYPE;
|
|
48
|
+
const host = process.env.DB_HOST;
|
|
49
|
+
const port = process.env.DB_PORT;
|
|
50
|
+
const username = process.env.DB_USERNAME;
|
|
51
|
+
const password = process.env.DB_PASSWORD;
|
|
52
|
+
const database = process.env.DB_DATABASE;
|
|
53
|
+
if (!host) throw new Error("DB_HOST is required!");
|
|
54
|
+
if (!port) throw new Error("DB_PORT is required!");
|
|
55
|
+
if (!username) throw new Error("DB_USERNAME is required!");
|
|
56
|
+
if (!password) throw new Error("DB_PASSWORD is required!");
|
|
57
|
+
if (!database) throw new Error("DB_DATABASE is required!");
|
|
58
|
+
const DB = new import_typeorm.DataSource({
|
|
59
|
+
...options || {},
|
|
60
|
+
type: type || "postgres",
|
|
61
|
+
host,
|
|
62
|
+
port: Number(port),
|
|
63
|
+
username,
|
|
64
|
+
password,
|
|
65
|
+
database,
|
|
66
|
+
synchronize: true,
|
|
67
|
+
migrationsRun: false,
|
|
68
|
+
logging: "all",
|
|
69
|
+
logger: "advanced-console",
|
|
70
|
+
migrations: [__dirname + "/**/migrations/*{.js,.ts}"],
|
|
71
|
+
applicationName: (0, import_os.hostname)()
|
|
72
|
+
});
|
|
73
|
+
DB.initialize().then(() => console.log("Data Source has been initialized!")).catch((err) => console.error("Error during Data Source initialization", err));
|
|
74
|
+
return DB;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/tools/response.ts
|
|
78
|
+
var responseWrapper = async (res, promise) => {
|
|
79
|
+
return promise.then((data) => {
|
|
80
|
+
res.status(200).send(data);
|
|
81
|
+
}).catch((err) => {
|
|
82
|
+
const status = err.statusCode || 422;
|
|
83
|
+
if (err.response && err.response.data) {
|
|
84
|
+
console.error(err.response);
|
|
85
|
+
return res.status(status).send(err.response.data);
|
|
86
|
+
}
|
|
87
|
+
console.error(err);
|
|
88
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/router/health.ts
|
|
93
|
+
var healthRouter = (router, options, done) => {
|
|
94
|
+
router.get("/", async (req, res) => {
|
|
95
|
+
return responseWrapper(
|
|
96
|
+
res,
|
|
97
|
+
new Promise((resolve) => {
|
|
98
|
+
resolve({ message: "OK" });
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
done();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/server/index.ts
|
|
106
|
+
var import_fastify = __toESM(require("fastify"));
|
|
107
|
+
var import_fastify_plugin = __toESM(require("fastify-plugin"));
|
|
108
|
+
var app = (0, import_fastify.default)();
|
|
109
|
+
var serverInit = (appConfig) => {
|
|
110
|
+
const PORT = process.env.HOST_PORT;
|
|
111
|
+
const VERSION = process.env.HOST_VERSION;
|
|
112
|
+
const DOMAIN = process.env.HOST_DOMAIN;
|
|
113
|
+
if (!PORT) throw new Error("HOST_PORT is required!");
|
|
114
|
+
if (!VERSION) throw new Error("HOST_VERSION is required!");
|
|
115
|
+
if (!DOMAIN) throw new Error("HOST_DOMAIN is required!");
|
|
116
|
+
app.register(
|
|
117
|
+
(0, import_fastify_plugin.default)(async (instance) => {
|
|
118
|
+
instance.addHook(
|
|
119
|
+
"onRequest",
|
|
120
|
+
(req, res, done) => {
|
|
121
|
+
console.log(`${res.statusCode < 400 ? "\u{1F7E2}" : "\u{1F534}"} ${res.statusCode} [${req.method}] - ${req.url}`);
|
|
122
|
+
done();
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
app.register(mainRouter, { prefix: VERSION });
|
|
128
|
+
app.setNotFoundHandler((req, res) => {
|
|
129
|
+
res.code(404).send({ status: 404, message: "Rote not found!" });
|
|
130
|
+
});
|
|
131
|
+
if (appConfig) appConfig(app);
|
|
132
|
+
const listenOptions = {
|
|
133
|
+
port: Number(PORT),
|
|
134
|
+
host: DOMAIN
|
|
135
|
+
};
|
|
136
|
+
app.listen(listenOptions, (err, address) => {
|
|
137
|
+
if (err) {
|
|
138
|
+
console.error("Error in server initialization!", err);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
console.log(`Server has been started in ${address}...`);
|
|
142
|
+
});
|
|
143
|
+
return app;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/router/api.ts
|
|
147
|
+
var import_lodash = __toESM(require("lodash"));
|
|
148
|
+
var apiRouter = (registers) => {
|
|
149
|
+
const apiPrefix = "api";
|
|
150
|
+
app.register((router, options, done) => {
|
|
151
|
+
import_lodash.default.forEach(registers, (register, prefix) => {
|
|
152
|
+
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
153
|
+
});
|
|
154
|
+
done();
|
|
155
|
+
}, { prefix: process.env.HOST_VERSION });
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/router/index.ts
|
|
159
|
+
var mainRouter = (router, options, done) => {
|
|
160
|
+
router.register(healthRouter, { prefix: "health" });
|
|
161
|
+
done();
|
|
162
|
+
};
|
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
164
|
+
0 && (module.exports = {
|
|
165
|
+
apiRouter,
|
|
166
|
+
app,
|
|
167
|
+
databaseInit,
|
|
168
|
+
mainRouter,
|
|
169
|
+
responseWrapper,
|
|
170
|
+
serverInit
|
|
171
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// src/database/index.ts
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { hostname } from "os";
|
|
4
|
+
import { DataSource } from "typeorm";
|
|
5
|
+
var databaseInit = (options) => {
|
|
6
|
+
const type = process.env.DB_TYPE;
|
|
7
|
+
const host = process.env.DB_HOST;
|
|
8
|
+
const port = process.env.DB_PORT;
|
|
9
|
+
const username = process.env.DB_USERNAME;
|
|
10
|
+
const password = process.env.DB_PASSWORD;
|
|
11
|
+
const database = process.env.DB_DATABASE;
|
|
12
|
+
if (!host) throw new Error("DB_HOST is required!");
|
|
13
|
+
if (!port) throw new Error("DB_PORT is required!");
|
|
14
|
+
if (!username) throw new Error("DB_USERNAME is required!");
|
|
15
|
+
if (!password) throw new Error("DB_PASSWORD is required!");
|
|
16
|
+
if (!database) throw new Error("DB_DATABASE is required!");
|
|
17
|
+
const DB = new DataSource({
|
|
18
|
+
...options || {},
|
|
19
|
+
type: type || "postgres",
|
|
20
|
+
host,
|
|
21
|
+
port: Number(port),
|
|
22
|
+
username,
|
|
23
|
+
password,
|
|
24
|
+
database,
|
|
25
|
+
synchronize: true,
|
|
26
|
+
migrationsRun: false,
|
|
27
|
+
logging: "all",
|
|
28
|
+
logger: "advanced-console",
|
|
29
|
+
migrations: [__dirname + "/**/migrations/*{.js,.ts}"],
|
|
30
|
+
applicationName: hostname()
|
|
31
|
+
});
|
|
32
|
+
DB.initialize().then(() => console.log("Data Source has been initialized!")).catch((err) => console.error("Error during Data Source initialization", err));
|
|
33
|
+
return DB;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/tools/response.ts
|
|
37
|
+
var responseWrapper = async (res, promise) => {
|
|
38
|
+
return promise.then((data) => {
|
|
39
|
+
res.status(200).send(data);
|
|
40
|
+
}).catch((err) => {
|
|
41
|
+
const status = err.statusCode || 422;
|
|
42
|
+
if (err.response && err.response.data) {
|
|
43
|
+
console.error(err.response);
|
|
44
|
+
return res.status(status).send(err.response.data);
|
|
45
|
+
}
|
|
46
|
+
console.error(err);
|
|
47
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/router/health.ts
|
|
52
|
+
var healthRouter = (router, options, done) => {
|
|
53
|
+
router.get("/", async (req, res) => {
|
|
54
|
+
return responseWrapper(
|
|
55
|
+
res,
|
|
56
|
+
new Promise((resolve) => {
|
|
57
|
+
resolve({ message: "OK" });
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
done();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/server/index.ts
|
|
65
|
+
import fastify from "fastify";
|
|
66
|
+
import fp from "fastify-plugin";
|
|
67
|
+
var app = fastify();
|
|
68
|
+
var serverInit = (appConfig) => {
|
|
69
|
+
const PORT = process.env.HOST_PORT;
|
|
70
|
+
const VERSION = process.env.HOST_VERSION;
|
|
71
|
+
const DOMAIN = process.env.HOST_DOMAIN;
|
|
72
|
+
if (!PORT) throw new Error("HOST_PORT is required!");
|
|
73
|
+
if (!VERSION) throw new Error("HOST_VERSION is required!");
|
|
74
|
+
if (!DOMAIN) throw new Error("HOST_DOMAIN is required!");
|
|
75
|
+
app.register(
|
|
76
|
+
fp(async (instance) => {
|
|
77
|
+
instance.addHook(
|
|
78
|
+
"onRequest",
|
|
79
|
+
(req, res, done) => {
|
|
80
|
+
console.log(`${res.statusCode < 400 ? "\u{1F7E2}" : "\u{1F534}"} ${res.statusCode} [${req.method}] - ${req.url}`);
|
|
81
|
+
done();
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
app.register(mainRouter, { prefix: VERSION });
|
|
87
|
+
app.setNotFoundHandler((req, res) => {
|
|
88
|
+
res.code(404).send({ status: 404, message: "Rote not found!" });
|
|
89
|
+
});
|
|
90
|
+
if (appConfig) appConfig(app);
|
|
91
|
+
const listenOptions = {
|
|
92
|
+
port: Number(PORT),
|
|
93
|
+
host: DOMAIN
|
|
94
|
+
};
|
|
95
|
+
app.listen(listenOptions, (err, address) => {
|
|
96
|
+
if (err) {
|
|
97
|
+
console.error("Error in server initialization!", err);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
console.log(`Server has been started in ${address}...`);
|
|
101
|
+
});
|
|
102
|
+
return app;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/router/api.ts
|
|
106
|
+
import _ from "lodash";
|
|
107
|
+
var apiRouter = (registers) => {
|
|
108
|
+
const apiPrefix = "api";
|
|
109
|
+
app.register((router, options, done) => {
|
|
110
|
+
_.forEach(registers, (register, prefix) => {
|
|
111
|
+
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
112
|
+
});
|
|
113
|
+
done();
|
|
114
|
+
}, { prefix: process.env.HOST_VERSION });
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/router/index.ts
|
|
118
|
+
var mainRouter = (router, options, done) => {
|
|
119
|
+
router.register(healthRouter, { prefix: "health" });
|
|
120
|
+
done();
|
|
121
|
+
};
|
|
122
|
+
export {
|
|
123
|
+
apiRouter,
|
|
124
|
+
app,
|
|
125
|
+
databaseInit,
|
|
126
|
+
mainRouter,
|
|
127
|
+
responseWrapper,
|
|
128
|
+
serverInit
|
|
129
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/database/index.ts
|
|
21
|
+
var database_exports = {};
|
|
22
|
+
__export(database_exports, {
|
|
23
|
+
databaseInit: () => databaseInit
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(database_exports);
|
|
26
|
+
var import_config = require("dotenv/config");
|
|
27
|
+
var import_os = require("os");
|
|
28
|
+
var import_typeorm = require("typeorm");
|
|
29
|
+
var databaseInit = (options) => {
|
|
30
|
+
const type = process.env.DB_TYPE;
|
|
31
|
+
const host = process.env.DB_HOST;
|
|
32
|
+
const port = process.env.DB_PORT;
|
|
33
|
+
const username = process.env.DB_USERNAME;
|
|
34
|
+
const password = process.env.DB_PASSWORD;
|
|
35
|
+
const database = process.env.DB_DATABASE;
|
|
36
|
+
if (!host) throw new Error("DB_HOST is required!");
|
|
37
|
+
if (!port) throw new Error("DB_PORT is required!");
|
|
38
|
+
if (!username) throw new Error("DB_USERNAME is required!");
|
|
39
|
+
if (!password) throw new Error("DB_PASSWORD is required!");
|
|
40
|
+
if (!database) throw new Error("DB_DATABASE is required!");
|
|
41
|
+
const DB = new import_typeorm.DataSource({
|
|
42
|
+
...options || {},
|
|
43
|
+
type: type || "postgres",
|
|
44
|
+
host,
|
|
45
|
+
port: Number(port),
|
|
46
|
+
username,
|
|
47
|
+
password,
|
|
48
|
+
database,
|
|
49
|
+
synchronize: true,
|
|
50
|
+
migrationsRun: false,
|
|
51
|
+
logging: "all",
|
|
52
|
+
logger: "advanced-console",
|
|
53
|
+
migrations: [__dirname + "/**/migrations/*{.js,.ts}"],
|
|
54
|
+
applicationName: (0, import_os.hostname)()
|
|
55
|
+
});
|
|
56
|
+
DB.initialize().then(() => console.log("Data Source has been initialized!")).catch((err) => console.error("Error during Data Source initialization", err));
|
|
57
|
+
return DB;
|
|
58
|
+
};
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
databaseInit
|
|
62
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/database/index.ts
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { hostname } from "os";
|
|
4
|
+
import { DataSource } from "typeorm";
|
|
5
|
+
var databaseInit = (options) => {
|
|
6
|
+
const type = process.env.DB_TYPE;
|
|
7
|
+
const host = process.env.DB_HOST;
|
|
8
|
+
const port = process.env.DB_PORT;
|
|
9
|
+
const username = process.env.DB_USERNAME;
|
|
10
|
+
const password = process.env.DB_PASSWORD;
|
|
11
|
+
const database = process.env.DB_DATABASE;
|
|
12
|
+
if (!host) throw new Error("DB_HOST is required!");
|
|
13
|
+
if (!port) throw new Error("DB_PORT is required!");
|
|
14
|
+
if (!username) throw new Error("DB_USERNAME is required!");
|
|
15
|
+
if (!password) throw new Error("DB_PASSWORD is required!");
|
|
16
|
+
if (!database) throw new Error("DB_DATABASE is required!");
|
|
17
|
+
const DB = new DataSource({
|
|
18
|
+
...options || {},
|
|
19
|
+
type: type || "postgres",
|
|
20
|
+
host,
|
|
21
|
+
port: Number(port),
|
|
22
|
+
username,
|
|
23
|
+
password,
|
|
24
|
+
database,
|
|
25
|
+
synchronize: true,
|
|
26
|
+
migrationsRun: false,
|
|
27
|
+
logging: "all",
|
|
28
|
+
logger: "advanced-console",
|
|
29
|
+
migrations: [__dirname + "/**/migrations/*{.js,.ts}"],
|
|
30
|
+
applicationName: hostname()
|
|
31
|
+
});
|
|
32
|
+
DB.initialize().then(() => console.log("Data Source has been initialized!")).catch((err) => console.error("Error during Data Source initialization", err));
|
|
33
|
+
return DB;
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
databaseInit
|
|
37
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FastifyInstance, FastifyListenOptions } from 'fastify';
|
|
2
|
+
|
|
3
|
+
declare const apiRouter: (registers: {
|
|
4
|
+
[prefix: string]: (router: FastifyInstance, options: FastifyListenOptions, done: () => void) => void;
|
|
5
|
+
}) => void;
|
|
6
|
+
|
|
7
|
+
declare const mainRouter: (router: FastifyInstance, options: FastifyListenOptions, done: () => void) => void;
|
|
8
|
+
|
|
9
|
+
export { apiRouter, mainRouter };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FastifyInstance, FastifyListenOptions } from 'fastify';
|
|
2
|
+
|
|
3
|
+
declare const apiRouter: (registers: {
|
|
4
|
+
[prefix: string]: (router: FastifyInstance, options: FastifyListenOptions, done: () => void) => void;
|
|
5
|
+
}) => void;
|
|
6
|
+
|
|
7
|
+
declare const mainRouter: (router: FastifyInstance, options: FastifyListenOptions, done: () => void) => void;
|
|
8
|
+
|
|
9
|
+
export { apiRouter, mainRouter };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/router/index.ts
|
|
31
|
+
var router_exports = {};
|
|
32
|
+
__export(router_exports, {
|
|
33
|
+
apiRouter: () => apiRouter,
|
|
34
|
+
mainRouter: () => mainRouter
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(router_exports);
|
|
37
|
+
|
|
38
|
+
// src/tools/response.ts
|
|
39
|
+
var responseWrapper = async (res, promise) => {
|
|
40
|
+
return promise.then((data) => {
|
|
41
|
+
res.status(200).send(data);
|
|
42
|
+
}).catch((err) => {
|
|
43
|
+
const status = err.statusCode || 422;
|
|
44
|
+
if (err.response && err.response.data) {
|
|
45
|
+
console.error(err.response);
|
|
46
|
+
return res.status(status).send(err.response.data);
|
|
47
|
+
}
|
|
48
|
+
console.error(err);
|
|
49
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/router/health.ts
|
|
54
|
+
var healthRouter = (router, options, done) => {
|
|
55
|
+
router.get("/", async (req, res) => {
|
|
56
|
+
return responseWrapper(
|
|
57
|
+
res,
|
|
58
|
+
new Promise((resolve) => {
|
|
59
|
+
resolve({ message: "OK" });
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
done();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/server/index.ts
|
|
67
|
+
var import_fastify = __toESM(require("fastify"));
|
|
68
|
+
var import_fastify_plugin = __toESM(require("fastify-plugin"));
|
|
69
|
+
var app = (0, import_fastify.default)();
|
|
70
|
+
|
|
71
|
+
// src/router/api.ts
|
|
72
|
+
var import_lodash = __toESM(require("lodash"));
|
|
73
|
+
var apiRouter = (registers) => {
|
|
74
|
+
const apiPrefix = "api";
|
|
75
|
+
app.register((router, options, done) => {
|
|
76
|
+
import_lodash.default.forEach(registers, (register, prefix) => {
|
|
77
|
+
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
78
|
+
});
|
|
79
|
+
done();
|
|
80
|
+
}, { prefix: process.env.HOST_VERSION });
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/router/index.ts
|
|
84
|
+
var mainRouter = (router, options, done) => {
|
|
85
|
+
router.register(healthRouter, { prefix: "health" });
|
|
86
|
+
done();
|
|
87
|
+
};
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
apiRouter,
|
|
91
|
+
mainRouter
|
|
92
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/tools/response.ts
|
|
2
|
+
var responseWrapper = async (res, promise) => {
|
|
3
|
+
return promise.then((data) => {
|
|
4
|
+
res.status(200).send(data);
|
|
5
|
+
}).catch((err) => {
|
|
6
|
+
const status = err.statusCode || 422;
|
|
7
|
+
if (err.response && err.response.data) {
|
|
8
|
+
console.error(err.response);
|
|
9
|
+
return res.status(status).send(err.response.data);
|
|
10
|
+
}
|
|
11
|
+
console.error(err);
|
|
12
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/router/health.ts
|
|
17
|
+
var healthRouter = (router, options, done) => {
|
|
18
|
+
router.get("/", async (req, res) => {
|
|
19
|
+
return responseWrapper(
|
|
20
|
+
res,
|
|
21
|
+
new Promise((resolve) => {
|
|
22
|
+
resolve({ message: "OK" });
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
done();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/server/index.ts
|
|
30
|
+
import fastify from "fastify";
|
|
31
|
+
import fp from "fastify-plugin";
|
|
32
|
+
var app = fastify();
|
|
33
|
+
|
|
34
|
+
// src/router/api.ts
|
|
35
|
+
import _ from "lodash";
|
|
36
|
+
var apiRouter = (registers) => {
|
|
37
|
+
const apiPrefix = "api";
|
|
38
|
+
app.register((router, options, done) => {
|
|
39
|
+
_.forEach(registers, (register, prefix) => {
|
|
40
|
+
router.register(register, { prefix: `${apiPrefix}/${prefix}` });
|
|
41
|
+
});
|
|
42
|
+
done();
|
|
43
|
+
}, { prefix: process.env.HOST_VERSION });
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/router/index.ts
|
|
47
|
+
var mainRouter = (router, options, done) => {
|
|
48
|
+
router.register(healthRouter, { prefix: "health" });
|
|
49
|
+
done();
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
apiRouter,
|
|
53
|
+
mainRouter
|
|
54
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as fastify from 'fastify';
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import * as http from 'http';
|
|
4
|
+
|
|
5
|
+
declare const app: FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault>>;
|
|
6
|
+
declare const serverInit: (appConfig?: (app: FastifyInstance) => void) => FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault>>;
|
|
7
|
+
|
|
8
|
+
export { app, serverInit };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as fastify from 'fastify';
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import * as http from 'http';
|
|
4
|
+
|
|
5
|
+
declare const app: FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault>>;
|
|
6
|
+
declare const serverInit: (appConfig?: (app: FastifyInstance) => void) => FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault>>;
|
|
7
|
+
|
|
8
|
+
export { app, serverInit };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/server/index.ts
|
|
31
|
+
var server_exports = {};
|
|
32
|
+
__export(server_exports, {
|
|
33
|
+
app: () => app,
|
|
34
|
+
serverInit: () => serverInit
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(server_exports);
|
|
37
|
+
var import_fastify = __toESM(require("fastify"));
|
|
38
|
+
|
|
39
|
+
// src/tools/response.ts
|
|
40
|
+
var responseWrapper = async (res, promise) => {
|
|
41
|
+
return promise.then((data) => {
|
|
42
|
+
res.status(200).send(data);
|
|
43
|
+
}).catch((err) => {
|
|
44
|
+
const status = err.statusCode || 422;
|
|
45
|
+
if (err.response && err.response.data) {
|
|
46
|
+
console.error(err.response);
|
|
47
|
+
return res.status(status).send(err.response.data);
|
|
48
|
+
}
|
|
49
|
+
console.error(err);
|
|
50
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/router/health.ts
|
|
55
|
+
var healthRouter = (router, options, done) => {
|
|
56
|
+
router.get("/", async (req, res) => {
|
|
57
|
+
return responseWrapper(
|
|
58
|
+
res,
|
|
59
|
+
new Promise((resolve) => {
|
|
60
|
+
resolve({ message: "OK" });
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
done();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/router/api.ts
|
|
68
|
+
var import_lodash = __toESM(require("lodash"));
|
|
69
|
+
|
|
70
|
+
// src/router/index.ts
|
|
71
|
+
var mainRouter = (router, options, done) => {
|
|
72
|
+
router.register(healthRouter, { prefix: "health" });
|
|
73
|
+
done();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/server/index.ts
|
|
77
|
+
var import_fastify_plugin = __toESM(require("fastify-plugin"));
|
|
78
|
+
var app = (0, import_fastify.default)();
|
|
79
|
+
var serverInit = (appConfig) => {
|
|
80
|
+
const PORT = process.env.HOST_PORT;
|
|
81
|
+
const VERSION = process.env.HOST_VERSION;
|
|
82
|
+
const DOMAIN = process.env.HOST_DOMAIN;
|
|
83
|
+
if (!PORT) throw new Error("HOST_PORT is required!");
|
|
84
|
+
if (!VERSION) throw new Error("HOST_VERSION is required!");
|
|
85
|
+
if (!DOMAIN) throw new Error("HOST_DOMAIN is required!");
|
|
86
|
+
app.register(
|
|
87
|
+
(0, import_fastify_plugin.default)(async (instance) => {
|
|
88
|
+
instance.addHook(
|
|
89
|
+
"onRequest",
|
|
90
|
+
(req, res, done) => {
|
|
91
|
+
console.log(`${res.statusCode < 400 ? "\u{1F7E2}" : "\u{1F534}"} ${res.statusCode} [${req.method}] - ${req.url}`);
|
|
92
|
+
done();
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
app.register(mainRouter, { prefix: VERSION });
|
|
98
|
+
app.setNotFoundHandler((req, res) => {
|
|
99
|
+
res.code(404).send({ status: 404, message: "Rote not found!" });
|
|
100
|
+
});
|
|
101
|
+
if (appConfig) appConfig(app);
|
|
102
|
+
const listenOptions = {
|
|
103
|
+
port: Number(PORT),
|
|
104
|
+
host: DOMAIN
|
|
105
|
+
};
|
|
106
|
+
app.listen(listenOptions, (err, address) => {
|
|
107
|
+
if (err) {
|
|
108
|
+
console.error("Error in server initialization!", err);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
console.log(`Server has been started in ${address}...`);
|
|
112
|
+
});
|
|
113
|
+
return app;
|
|
114
|
+
};
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
app,
|
|
118
|
+
serverInit
|
|
119
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/server/index.ts
|
|
2
|
+
import fastify from "fastify";
|
|
3
|
+
|
|
4
|
+
// src/tools/response.ts
|
|
5
|
+
var responseWrapper = async (res, promise) => {
|
|
6
|
+
return promise.then((data) => {
|
|
7
|
+
res.status(200).send(data);
|
|
8
|
+
}).catch((err) => {
|
|
9
|
+
const status = err.statusCode || 422;
|
|
10
|
+
if (err.response && err.response.data) {
|
|
11
|
+
console.error(err.response);
|
|
12
|
+
return res.status(status).send(err.response.data);
|
|
13
|
+
}
|
|
14
|
+
console.error(err);
|
|
15
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// src/router/health.ts
|
|
20
|
+
var healthRouter = (router, options, done) => {
|
|
21
|
+
router.get("/", async (req, res) => {
|
|
22
|
+
return responseWrapper(
|
|
23
|
+
res,
|
|
24
|
+
new Promise((resolve) => {
|
|
25
|
+
resolve({ message: "OK" });
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
done();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/router/api.ts
|
|
33
|
+
import _ from "lodash";
|
|
34
|
+
|
|
35
|
+
// src/router/index.ts
|
|
36
|
+
var mainRouter = (router, options, done) => {
|
|
37
|
+
router.register(healthRouter, { prefix: "health" });
|
|
38
|
+
done();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/server/index.ts
|
|
42
|
+
import fp from "fastify-plugin";
|
|
43
|
+
var app = fastify();
|
|
44
|
+
var serverInit = (appConfig) => {
|
|
45
|
+
const PORT = process.env.HOST_PORT;
|
|
46
|
+
const VERSION = process.env.HOST_VERSION;
|
|
47
|
+
const DOMAIN = process.env.HOST_DOMAIN;
|
|
48
|
+
if (!PORT) throw new Error("HOST_PORT is required!");
|
|
49
|
+
if (!VERSION) throw new Error("HOST_VERSION is required!");
|
|
50
|
+
if (!DOMAIN) throw new Error("HOST_DOMAIN is required!");
|
|
51
|
+
app.register(
|
|
52
|
+
fp(async (instance) => {
|
|
53
|
+
instance.addHook(
|
|
54
|
+
"onRequest",
|
|
55
|
+
(req, res, done) => {
|
|
56
|
+
console.log(`${res.statusCode < 400 ? "\u{1F7E2}" : "\u{1F534}"} ${res.statusCode} [${req.method}] - ${req.url}`);
|
|
57
|
+
done();
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
app.register(mainRouter, { prefix: VERSION });
|
|
63
|
+
app.setNotFoundHandler((req, res) => {
|
|
64
|
+
res.code(404).send({ status: 404, message: "Rote not found!" });
|
|
65
|
+
});
|
|
66
|
+
if (appConfig) appConfig(app);
|
|
67
|
+
const listenOptions = {
|
|
68
|
+
port: Number(PORT),
|
|
69
|
+
host: DOMAIN
|
|
70
|
+
};
|
|
71
|
+
app.listen(listenOptions, (err, address) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
console.error("Error in server initialization!", err);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
console.log(`Server has been started in ${address}...`);
|
|
77
|
+
});
|
|
78
|
+
return app;
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
app,
|
|
82
|
+
serverInit
|
|
83
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/tools/index.ts
|
|
21
|
+
var tools_exports = {};
|
|
22
|
+
__export(tools_exports, {
|
|
23
|
+
responseWrapper: () => responseWrapper
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tools_exports);
|
|
26
|
+
|
|
27
|
+
// src/tools/response.ts
|
|
28
|
+
var responseWrapper = async (res, promise) => {
|
|
29
|
+
return promise.then((data) => {
|
|
30
|
+
res.status(200).send(data);
|
|
31
|
+
}).catch((err) => {
|
|
32
|
+
const status = err.statusCode || 422;
|
|
33
|
+
if (err.response && err.response.data) {
|
|
34
|
+
console.error(err.response);
|
|
35
|
+
return res.status(status).send(err.response.data);
|
|
36
|
+
}
|
|
37
|
+
console.error(err);
|
|
38
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
responseWrapper
|
|
44
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/tools/response.ts
|
|
2
|
+
var responseWrapper = async (res, promise) => {
|
|
3
|
+
return promise.then((data) => {
|
|
4
|
+
res.status(200).send(data);
|
|
5
|
+
}).catch((err) => {
|
|
6
|
+
const status = err.statusCode || 422;
|
|
7
|
+
if (err.response && err.response.data) {
|
|
8
|
+
console.error(err.response);
|
|
9
|
+
return res.status(status).send(err.response.data);
|
|
10
|
+
}
|
|
11
|
+
console.error(err);
|
|
12
|
+
return res.status(status).send({ message: err.message, type: err.type, code: err.code });
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
responseWrapper
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gustavo-valsechi/node",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"license": "UNLICENSED",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"clean": "rimraf dist && rimraf node_modules/.cache",
|
|
13
|
+
"build:js": "tsup && tsc-alias",
|
|
14
|
+
"build": "npm run clean && npm run build:js",
|
|
15
|
+
"commit": "npm run build && npm version patch --no-git-tag-version && npm publish --access public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"body-parser": "2.2.1",
|
|
19
|
+
"dotenv": "16.4.5",
|
|
20
|
+
"fastify": "4.27.0",
|
|
21
|
+
"fastify-plugin": "4.5.1",
|
|
22
|
+
"lodash": "4.17.21",
|
|
23
|
+
"pg": "8.11.5",
|
|
24
|
+
"typeorm": "0.3.26",
|
|
25
|
+
"uuid": "9.0.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/lodash": "4.17.0",
|
|
29
|
+
"@types/morgan": "1.9.9",
|
|
30
|
+
"@types/node": "20.12.7",
|
|
31
|
+
"@types/uuid": "9.0.8",
|
|
32
|
+
"eslint": "9.1.1",
|
|
33
|
+
"morgan": "1.10.0",
|
|
34
|
+
"typescript": "5.4.5",
|
|
35
|
+
"vitest": "3.0.5",
|
|
36
|
+
"rimraf": "6.1.0",
|
|
37
|
+
"tsc-alias": "1.8.16",
|
|
38
|
+
"tsup": "8.5.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"require": "./dist/index.js",
|
|
47
|
+
"import": "./dist/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./database": {
|
|
50
|
+
"types": "./dist/src/database/index.d.ts",
|
|
51
|
+
"require": "./dist/src/database/index.js",
|
|
52
|
+
"import": "./dist/src/database/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./router": {
|
|
55
|
+
"types": "./dist/src/router/index.d.ts",
|
|
56
|
+
"require": "./dist/src/router/index.js",
|
|
57
|
+
"import": "./dist/src/router/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./server": {
|
|
60
|
+
"types": "./dist/src/server/index.d.ts",
|
|
61
|
+
"require": "./dist/src/server/index.js",
|
|
62
|
+
"import": "./dist/src/server/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./tools": {
|
|
65
|
+
"types": "./dist/src/tools/index.d.ts",
|
|
66
|
+
"require": "./dist/src/tools/index.js",
|
|
67
|
+
"import": "./dist/src/tools/index.js"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|