mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-21 05:00:56 +00:00
feat(infisical-pg): added e2e test setup
This commit is contained in:
+3
@@ -16,4 +16,7 @@ declare global {
|
||||
Readonly<Logger>,
|
||||
ZodTypeProvider
|
||||
>;
|
||||
|
||||
// used only for testing
|
||||
const testServer: FastifyZodProvider;
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -40,7 +40,7 @@ import {
|
||||
} from "@app/db/schemas";
|
||||
|
||||
declare module "knex/types/tables" {
|
||||
interface Tables extends { [key in TableName]: Knex.CompositeTableType<any> } {
|
||||
interface Tables {
|
||||
[TableName.Users]: Knex.CompositeTableType<TUsers, TUsersInsert, TUsersUpdate>;
|
||||
[TableName.UserEncryptionKey]: Knex.CompositeTableType<
|
||||
TUserEncryptionKeys,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import dotenv from "dotenv";
|
||||
|
||||
import { formatSmtpConfig, initEnvConfig } from "./lib/config/env";
|
||||
import { initLogger } from "./lib/logger";
|
||||
import { main } from "./server/app";
|
||||
import { smtpServiceFactory } from "./services/smtp/smtp-service";
|
||||
import { initDbConnection } from "./db";
|
||||
|
||||
dotenv.config();
|
||||
const run = async () => {
|
||||
const logger = await initLogger();
|
||||
const appCfg = initEnvConfig(logger);
|
||||
const db = initDbConnection(appCfg.DB_CONNECTION_URI);
|
||||
const smtp = smtpServiceFactory(formatSmtpConfig());
|
||||
|
||||
const server = await main({ db, smtp, logger });
|
||||
process.on("SIGINT", async () => {
|
||||
await server.close();
|
||||
await db.destroy();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", async () => {
|
||||
await server.close();
|
||||
await db.destroy();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
await server.listen({ port: appCfg.PORT, host: appCfg.HOST });
|
||||
};
|
||||
|
||||
run();
|
||||
@@ -1,5 +1,6 @@
|
||||
import dotenv from "dotenv";
|
||||
import fasitfy from "fastify";
|
||||
import { Knex } from "knex";
|
||||
import { Logger } from "pino";
|
||||
import type { FastifyCookieOptions } from "@fastify/cookie";
|
||||
import cookie from "@fastify/cookie";
|
||||
import type { FastifyCorsOptions } from "@fastify/cors";
|
||||
@@ -8,11 +9,9 @@ import helmet from "@fastify/helmet";
|
||||
import type { FastifyRateLimitOptions } from "@fastify/rate-limit";
|
||||
import ratelimiter from "@fastify/rate-limit";
|
||||
|
||||
import { initDbConnection } from "@app/db";
|
||||
import { smtpServiceFactory } from "@app/services/smtp/smtp-service";
|
||||
import { TSmtpService } from "@app/services/smtp/smtp-service";
|
||||
|
||||
import { formatSmtpConfig, initEnvConfig } from "@lib/config/env";
|
||||
import { initLogger } from "@lib/logger";
|
||||
import { getConfig } from "@lib/config/env";
|
||||
|
||||
import { globalRateLimiterCfg } from "./config/rateLimiter";
|
||||
import { serializerCompiler, validatorCompiler, ZodTypeProvider } from "./plugins/fastify-zod";
|
||||
@@ -20,13 +19,15 @@ import { fastifyIp } from "./plugins/ip";
|
||||
import { fastifySwagger } from "./plugins/swagger";
|
||||
import { registerRoutes } from "./routes";
|
||||
|
||||
dotenv.config();
|
||||
type TMain = {
|
||||
db: Knex;
|
||||
smtp: TSmtpService;
|
||||
logger?: Logger;
|
||||
};
|
||||
|
||||
// Run the server!
|
||||
const main = async () => {
|
||||
const logger = await initLogger();
|
||||
const envCfg = initEnvConfig(logger);
|
||||
|
||||
export const main = async ({ db, smtp, logger }: TMain) => {
|
||||
const appCfg = getConfig();
|
||||
const server = fasitfy({
|
||||
logger,
|
||||
trustProxy: true
|
||||
@@ -35,12 +36,9 @@ const main = async () => {
|
||||
server.setValidatorCompiler(validatorCompiler);
|
||||
server.setSerializerCompiler(serializerCompiler);
|
||||
|
||||
const db = initDbConnection(envCfg.DB_CONNECTION_URI);
|
||||
const smtp = smtpServiceFactory(formatSmtpConfig());
|
||||
|
||||
try {
|
||||
await server.register<FastifyCookieOptions>(cookie, {
|
||||
secret: envCfg.COOKIE_SECRET_SIGN_KEY
|
||||
secret: appCfg.COOKIE_SECRET_SIGN_KEY
|
||||
});
|
||||
|
||||
await server.register<FastifyCorsOptions>(cors, {
|
||||
@@ -59,11 +57,9 @@ const main = async () => {
|
||||
await server.register(registerRoutes, { prefix: "/api", smtp, db });
|
||||
await server.ready();
|
||||
server.swagger();
|
||||
await server.listen({ port: envCfg.PORT, host: envCfg.HOST });
|
||||
return server;
|
||||
} catch (err) {
|
||||
server.log.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user