From 8fec21d6bccfa778c14c1714d6444312e36fc3f1 Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Sun, 11 Feb 2024 19:15:20 +0530 Subject: more updates --- config/app.ts | 84 ++--------------------------- config/auth.ts | 9 ++-- config/bodyparser.ts | 2 - config/dashboard.ts | 2 +- config/database.ts | 8 +-- config/drive.ts | 149 --------------------------------------------------- config/hash.ts | 7 +-- config/logger.ts | 14 +++++ config/mail.ts | 111 +++++++++----------------------------- config/session.ts | 4 +- 10 files changed, 53 insertions(+), 337 deletions(-) delete mode 100644 config/drive.ts create mode 100644 config/logger.ts (limited to 'config') diff --git a/config/app.ts b/config/app.ts index 5575bc1..278a6f8 100644 --- a/config/app.ts +++ b/config/app.ts @@ -7,8 +7,6 @@ import proxyAddr from 'proxy-addr'; import env from '#start/env'; -import { ProfilerConfig } from '@ioc:Adonis/Core/Profiler'; -import { LoggerConfig } from '@adonisjs/core/types/logger'; import { ValidatorConfig } from '@adonisjs/validator/types'; import { defineConfig } from '@adonisjs/core/http'; @@ -27,12 +25,12 @@ import { defineConfig } from '@adonisjs/core/http'; */ export const appKey: string = env.get('APP_KEY'); -export const url: string = env.get('APP_URL'); +export const url = env.get('APP_URL'); // TODO: this is parsed as string to be coherent with the previous version of the code we add (before migrating to AdonisJS 5) -export const isRegistrationEnabled: string = env.get('IS_REGISTRATION_ENABLED'); -export const connectWithFranz: string = env.get('CONNECT_WITH_FRANZ'); -export const isCreationEnabled: string = env.get('IS_CREATION_ENABLED'); +export const isRegistrationEnabled = env.get('IS_REGISTRATION_ENABLED'); +export const connectWithFranz = env.get('CONNECT_WITH_FRANZ'); +export const isCreationEnabled = env.get('IS_CREATION_ENABLED'); export const jwtUsePEM: boolean = env.get('JWT_USE_PEM', false) || (env.get('JWT_PUBLIC_KEY', '') !== '' && @@ -119,86 +117,14 @@ export const http = defineConfig({ secure: false, sameSite: false, }, - - /* - |-------------------------------------------------------------------------- - | Force Content Negotiation - |-------------------------------------------------------------------------- - | - | The internals of the framework relies on the content negotiation to - | detect the best possible response type for a given HTTP request. - | - | However, it is a very common these days that API servers always wants to - | make response in JSON regardless of the existence of the `Accept` header. - | - | By setting `forceContentNegotiationTo = 'application/json'`, you negotiate - | with the server in advance to always return JSON without relying on the - | client to set the header explicitly. - | - */ - forceContentNegotiationTo: 'application/json', }); -/* -|-------------------------------------------------------------------------- -| Logger -|-------------------------------------------------------------------------- -*/ -export const logger: LoggerConfig = { - /* - |-------------------------------------------------------------------------- - | Application name - |-------------------------------------------------------------------------- - | - | The name of the application you want to add to the log. It is recommended - | to always have app name in every log line. - | - | The `APP_NAME` environment variable is automatically set by AdonisJS by - | reading the `name` property from the `package.json` file. - | - */ - name: env.get('APP_NAME', 'Ferdium-server'), - - /* - |-------------------------------------------------------------------------- - | Toggle logger - |-------------------------------------------------------------------------- - | - | Enable or disable logger application wide - | - */ - enabled: true, - - /* - |-------------------------------------------------------------------------- - | Logging level - |-------------------------------------------------------------------------- - | - | The level from which you want the logger to flush logs. It is recommended - | to make use of the environment variable, so that you can define log levels - | at deployment level and not code level. - | - */ - level: env.get('LOG_LEVEL', 'info'), - - /* - |-------------------------------------------------------------------------- - | Pretty print - |-------------------------------------------------------------------------- - | - | It is highly advised NOT to use `prettyPrint` in production, since it - | can have huge impact on performance. - | - */ - prettyPrint: env.get('NODE_ENV') === 'development', -}; - /* |-------------------------------------------------------------------------- | Profiler |-------------------------------------------------------------------------- */ -export const profiler: ProfilerConfig = { +export const profiler = { /* |-------------------------------------------------------------------------- | Toggle profiler diff --git a/config/auth.ts b/config/auth.ts index a3fcc45..976aa19 100644 --- a/config/auth.ts +++ b/config/auth.ts @@ -79,7 +79,7 @@ const authConfig: AuthConfig = { | that time. | */ - model: () => import('App/Models/User'), + model: () => import('#app/Models/User'), }, }, /* @@ -163,7 +163,7 @@ const authConfig: AuthConfig = { | that time. | */ - model: () => import('App/Models/User'), + model: () => import('#app/Models/User'), }, }, /* @@ -226,7 +226,7 @@ const authConfig: AuthConfig = { | that time. | */ - model: () => import('App/Models/User'), + model: () => import('#app/Models/User'), }, }, jwt: { @@ -242,7 +242,6 @@ const authConfig: AuthConfig = { persistJwt: true, // TODO: We should improve the following implementation as this is a security concern. // The following ts-expect-error is to set exp to undefined (JWT with no expiration) - // @ts-expect-error jwtDefaultExpire: undefined, refreshTokenDefaultExpire: '10d', tokenProvider: { @@ -254,7 +253,7 @@ const authConfig: AuthConfig = { driver: 'lucid', identifierKey: 'id', uids: [], - model: () => import('App/Models/User'), + model: () => import('#app/Models/User'), }, }, }, diff --git a/config/bodyparser.ts b/config/bodyparser.ts index b8e6ed6..63fc03c 100644 --- a/config/bodyparser.ts +++ b/config/bodyparser.ts @@ -5,7 +5,6 @@ * file. */ -import { BodyParserConfig } from '@adonisjs/core/bodyparser'; import { defineConfig } from '@adonisjs/core/bodyparser'; const bodyParserConfig = defineConfig({ @@ -83,7 +82,6 @@ const bodyParserConfig = defineConfig({ raw: { encoding: 'utf8', limit: '1mb', - queryString: {}, types: ['text/*'], }, diff --git a/config/dashboard.ts b/config/dashboard.ts index bbf7a71..5d3afbb 100644 --- a/config/dashboard.ts +++ b/config/dashboard.ts @@ -2,4 +2,4 @@ import env from '#start/env'; export const enabled: boolean = env.get('IS_DASHBOARD_ENABLED') !== 'false'; -export const mailFrom: string = env.get('MAIL_SENDER'); +export const mailFrom: string = env.get('MAIL_SENDER')!; diff --git a/config/database.ts b/config/database.ts index 7e3774d..d2fabe1 100644 --- a/config/database.ts +++ b/config/database.ts @@ -7,7 +7,6 @@ import path from 'node:path'; import env from '#start/env'; -import { DatabaseConfig } from '@adonisjs/lucid/database'; import { defineConfig } from '@adonisjs/lucid'; const databaseConfig = defineConfig({ @@ -53,7 +52,6 @@ const databaseConfig = defineConfig({ }, useNullAsDefault: true, healthCheck: false, - debug: env.get('DB_DEBUG', false), }, /* @@ -71,7 +69,7 @@ const databaseConfig = defineConfig({ client: 'mysql', connection: { host: env.get('DB_HOST', 'localhost'), - port: env.get('DB_PORT', ''), + port: Number(env.get('DB_PORT')), user: env.get('DB_USER', 'root'), password: env.get('DB_PASSWORD', ''), database: env.get('DB_DATABASE', 'ferdium'), @@ -80,7 +78,6 @@ const databaseConfig = defineConfig({ naturalSort: true, }, healthCheck: false, - debug: env.get('DB_DEBUG', false), }, /* @@ -98,7 +95,7 @@ const databaseConfig = defineConfig({ client: 'pg', connection: { host: env.get('DB_HOST', 'localhost'), - port: env.get('DB_PORT', ''), + port: Number(env.get('DB_PORT')), user: env.get('DB_USER', 'root'), password: env.get('DB_PASSWORD', ''), database: env.get('DB_DATABASE', 'ferdium'), @@ -113,7 +110,6 @@ const databaseConfig = defineConfig({ naturalSort: true, }, healthCheck: false, - debug: env.get('DB_DEBUG', false), }, }, }); diff --git a/config/drive.ts b/config/drive.ts deleted file mode 100644 index 98cc905..0000000 --- a/config/drive.ts +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Config source: https://git.io/JBt3o - * - * Feel free to let us know via PR, if you find something broken in this config - * file. - */ - -import env from '#start/env'; -import { driveConfig } from '@adonisjs/core/build/config'; -import { app } from '@adonisjs/core/services/app'; - -/* -|-------------------------------------------------------------------------- -| Drive Config -|-------------------------------------------------------------------------- -| -| The `DriveConfig` relies on the `DisksList` interface which is -| defined inside the `contracts` directory. -| -*/ -export default driveConfig({ - /* - |-------------------------------------------------------------------------- - | Default disk - |-------------------------------------------------------------------------- - | - | The default disk to use for managing file uploads. The value is driven by - | the `DRIVE_DISK` environment variable. - | - */ - disk: env.get('DRIVE_DISK', 'local'), - - disks: { - /* - |-------------------------------------------------------------------------- - | Local - |-------------------------------------------------------------------------- - | - | Uses the local file system to manage files. Make sure to turn off serving - | files when not using this disk. - | - */ - local: { - driver: 'local', - visibility: 'public', - - /* - |-------------------------------------------------------------------------- - | Storage root - Local driver only - |-------------------------------------------------------------------------- - | - | Define an absolute path to the storage directory from where to read the - | files. - | - */ - root: app.tmpPath('uploads'), - - /* - |-------------------------------------------------------------------------- - | Serve files - Local driver only - |-------------------------------------------------------------------------- - | - | When this is set to true, AdonisJS will configure a files server to serve - | files from the disk root. This is done to mimic the behavior of cloud - | storage services that has inbuilt capabilities to serve files. - | - */ - serveFiles: true, - - /* - |-------------------------------------------------------------------------- - | Base path - Local driver only - |-------------------------------------------------------------------------- - | - | Base path is always required when "serveFiles = true". Also make sure - | the `basePath` is unique across all the disks using "local" driver and - | you are not registering routes with this prefix. - | - */ - basePath: '/uploads', - }, - - /* - |-------------------------------------------------------------------------- - | S3 Driver - |-------------------------------------------------------------------------- - | - | Uses the S3 cloud storage to manage files. Make sure to install the s3 - | drive separately when using it. - | - |************************************************************************** - | npm i @adonisjs/drive-s3 - |************************************************************************** - | - */ - // s3: { - // driver: 's3', - // visibility: 'public', - // key: Env.get('S3_KEY'), - // secret: Env.get('S3_SECRET'), - // region: Env.get('S3_REGION'), - // bucket: Env.get('S3_BUCKET'), - // endpoint: Env.get('S3_ENDPOINT'), - // - // // For minio to work - // // forcePathStyle: true, - // }, - - /* - |-------------------------------------------------------------------------- - | GCS Driver - |-------------------------------------------------------------------------- - | - | Uses the Google cloud storage to manage files. Make sure to install the GCS - | drive separately when using it. - | - |************************************************************************** - | npm i @adonisjs/drive-gcs - |************************************************************************** - | - */ - // gcs: { - // driver: 'gcs', - // visibility: 'public', - // keyFilename: Env.get('GCS_KEY_FILENAME'), - // bucket: Env.get('GCS_BUCKET'), - - /* - |-------------------------------------------------------------------------- - | Uniform ACL - Google cloud storage only - |-------------------------------------------------------------------------- - | - | When using the Uniform ACL on the bucket, the "visibility" option is - | ignored. Since, the files ACL is managed by the google bucket policies - | directly. - | - |************************************************************************** - | Learn more: https://cloud.google.com/storage/docs/uniform-bucket-level-access - |************************************************************************** - | - | The following option just informs drive whether your bucket is using uniform - | ACL or not. The actual setting needs to be toggled within the Google cloud - | console. - | - */ - // usingUniformAcl: false, - // }, - }, -}); diff --git a/config/hash.ts b/config/hash.ts index 38c8784..891833c 100644 --- a/config/hash.ts +++ b/config/hash.ts @@ -6,8 +6,7 @@ */ import env from '#start/env'; -import { defineConfig } from '@adonisjs/core/hash'; -import { drivers } from '@adonisjs/core/hash'; +import { defineConfig, drivers } from '@adonisjs/core/hash'; /* |-------------------------------------------------------------------------- @@ -84,7 +83,3 @@ export default defineConfig({ }, }, }); - -declare module '@adonisjs/core/types' { - export interface HashersList extends InferHashers {} -} diff --git a/config/logger.ts b/config/logger.ts new file mode 100644 index 0000000..a9078b6 --- /dev/null +++ b/config/logger.ts @@ -0,0 +1,14 @@ +import env from '#start/env'; +import { defineConfig } from '@adonisjs/core/logger'; + +export default defineConfig({ + default: 'app', + + loggers: { + app: { + enabled: true, + name: env.get('APP_NAME', 'Ferdium-server'), + level: env.get('LOG_LEVEL', 'info'), + }, + }, +}); diff --git a/config/mail.ts b/config/mail.ts index ac67231..dbe4bdf 100644 --- a/config/mail.ts +++ b/config/mail.ts @@ -1,118 +1,55 @@ -/** - * Config source: https://git.io/JvgAf - * - * Feel free to let us know via PR, if you find something broken in this contract - * file. - */ - import env from '#start/env'; -import { defineConfig } from '@adonisjs/mail'; +import { defineConfig, transports } from '@adonisjs/mail'; -export default defineConfig({ - /* - |-------------------------------------------------------------------------- - | Default mailer - |-------------------------------------------------------------------------- - | - | The following mailer will be used to send emails, when you don't specify - | a mailer - | - */ - mailer: env.get('MAIL_CONNECTION', 'smtp'), +const mailConfig = defineConfig({ + default: 'smtp', - /* - |-------------------------------------------------------------------------- - | Mailers - |-------------------------------------------------------------------------- - | - | You can define or more mailers to send emails from your application. A - | single `driver` can be used to define multiple mailers with different - | config. - | - | For example: Postmark driver can be used to have different mailers for - | sending transactional and promotional emails - | - */ + /** + * The mailers object can be used to configure multiple mailers + * each using a different transport or same transport with different + * options. + */ mailers: { - /* - |-------------------------------------------------------------------------- - | Smtp - |-------------------------------------------------------------------------- - | - | Uses SMTP protocol for sending email - | - */ - smtp: drivers.smtp({ - name: env.get('APP_URL'), + smtp: transports.smtp({ port: env.get('SMTP_PORT', '2525'), host: env.get('SMTP_HOST', 'localhost'), secure: JSON.parse(env.get('MAIL_SSL', 'false')), requireTLS: JSON.parse(env.get('MAIL_REQUIRE_TLS', 'false')), auth: { - user: env.get('MAIL_USERNAME'), - pass: env.get('MAIL_PASSWORD'), + user: env.get('MAIL_USERNAME')!, + pass: env.get('MAIL_PASSWORD')!, type: 'login', }, maxConnections: 5, maxMessages: 100, - rateLimit: 10, }), - /* - |-------------------------------------------------------------------------- - | SES - |-------------------------------------------------------------------------- - | - | Uses Amazon SES for sending emails. You will have to install the aws-sdk - | when using this driver. - | - | ``` - | npm i aws-sdk - | ``` - | - */ - ses: drivers.ses({ + ses: transports.ses({ apiVersion: '2010-12-01', - key: env.get('SES_ACCESS_KEY'), - secret: env.get('SES_ACCESS_SECRET'), - region: env.get('SES_REGION'), - sslEnabled: true, + credentials: { + accessKeyId: env.get('SES_ACCESS_KEY')!, + secretAccessKey: env.get('SES_ACCESS_SECRET')!, + }, + region: process.env.SES_REGION!, sendingRate: 10, maxConnections: 5, }), - /* - |-------------------------------------------------------------------------- - | Mailgun - |-------------------------------------------------------------------------- - | - | Uses Mailgun service for sending emails. - | - | If you are using an EU domain. Ensure to change the baseUrl to hit the - | europe endpoint (https://api.eu.mailgun.net/v3). - | - */ - mailgun: drivers.mailgun({ + mailgun: transports.mailgun({ baseUrl: 'https://api.mailgun.net/v3', - key: env.get('MAILGUN_API_KEY'), - domain: env.get('MAILGUN_DOMAIN'), + key: env.get('MAILGUN_API_KEY')!, + domain: env.get('MAILGUN_DOMAIN')!, }), - /* - |-------------------------------------------------------------------------- - | SparkPost - |-------------------------------------------------------------------------- - | - | Uses Sparkpost service for sending emails. - | - */ - sparkpost: drivers.sparkpost({ + sparkpost: transports.sparkpost({ baseUrl: 'https://api.sparkpost.com/api/v1', - key: env.get('SPARKPOST_API_KEY'), + key: env.get('SPARKPOST_API_KEY')!, }), }, }); +export default mailConfig; + declare module '@adonisjs/mail/types' { export interface MailersList extends InferMailers {} } diff --git a/config/session.ts b/config/session.ts index d3f5642..3f193dd 100644 --- a/config/session.ts +++ b/config/session.ts @@ -6,7 +6,7 @@ */ import env from '#start/env'; -import { app } from '@adonisjs/core/services/app'; +import app from '@adonisjs/core/services/app'; import { defineConfig } from '@adonisjs/session'; export default defineConfig({ @@ -36,7 +36,7 @@ export default defineConfig({ | Note: Switching drivers will make existing sessions invalid. | */ - driver: env.get('SESSION_DRIVER', 'cookie'), + store: env.get('SESSION_DRIVER', 'cookie'), /* |-------------------------------------------------------------------------- -- cgit v1.2.3-54-g00ecf