Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmxcdev authored and vraravam committed Feb 11, 2024
1 parent d47e09f commit c3950f6
Show file tree
Hide file tree
Showing 33 changed files with 1,609 additions and 605 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ DATA_DIR=data
APP_KEY= # Need to set some value
HOST=127.0.0.1
PORT=3333
LOG_LEVEL=info

# These have defaults hard-coded, but are being overridden
CACHE_VIEWS=false
SESSION_DRIVER=cookie
SES_ACCESS_KEY=
SES_ACCESS_SECRET=
SES_REGION=
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
SPARKPOST_API_KEY=
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
},
],
'no-param-reassign': 1,
'prefer-destructuring': 1,
'prefer-destructuring': 0,
// eslint-plugin-unicorn
'unicorn/filename-case': 0,
'unicorn/prefer-module': 0,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Use Node.js specified in the '.nvmrc' file
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: Install node dependencies recursively
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.11.0-alpine as builder
FROM node:20.11.0-alpine AS builder

WORKDIR /server-build

Expand Down
6 changes: 2 additions & 4 deletions adonisrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
() => import('@adonisjs/core/commands'),
() => import('@adonisjs/lucid/commands'),
() => import('@adonisjs/mail/commands'),
() => import('adonis5-jwt/build/commands'),
// () => import('adonis5-jwt/build/commands'),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -39,7 +39,6 @@ export default defineConfig({
|
*/
providers: [
() => import('./providers/AppProvider.js'),
() => import('@adonisjs/core/providers/app_provider'),
() => import('@adonisjs/core/providers/hash_provider'),
{
Expand All @@ -52,8 +51,7 @@ export default defineConfig({
() => import('@adonisjs/shield/shield_provider'),
() => import('@adonisjs/session/session_provider'),
() => import('@adonisjs/mail/mail_provider'),
() => import('adonis5-jwt'),
() => import('./providers/LegacyHasherProvider.js'),
// () => import('adonis5-jwt'),
],
metaFiles: [
{
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Http/Api/Static/AnnouncementsController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HttpContext } from '@adonisjs/core/http';
import { app } from '@adonisjs/core/services/app';
import app from '@adonisjs/core/services/app';
import path from 'node:path';
import fs from 'fs-extra';

Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Http/RecipeController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HttpContext } from '@adonisjs/core/http';
import fs from 'fs-extra';
import { app } from '@adonisjs/core/services/app';
import app from '@adonisjs/core/services/app';
import path from 'node:path';
import Recipe from '#app/Models/Recipe';
import { isCreationEnabled } from '#config/app';
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Http/ServiceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { url } from '#config/app';
import { v4 as uuid } from 'uuid';
import * as fs from 'fs-extra';
import path from 'node:path';
import { app } from '@adonisjs/core/services/app';
import app from '@adonisjs/core/services/app';
import sanitize from 'sanitize-filename';

const createSchema = schema.create({
Expand Down
23 changes: 0 additions & 23 deletions app/Exceptions/Handler.ts

This file was deleted.

3 changes: 2 additions & 1 deletion app/Middleware/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpContext } from '@adonisjs/core/http';
import { AuthenticationException } from '@adonisjs/auth/build/standalone';
import * as jose from 'jose';
import { appKey } from '#config/app';
import User from '#app/Models/User';
import User from '#models/User';

/**
* Auth middleware is meant to restrict un-authenticated access to a given route
Expand Down Expand Up @@ -94,6 +94,7 @@ export default class AuthMiddleware {
/**
* Handle request
*/
// eslint-disable-next-line consistent-return
public async handle(
{ request, auth, response }: HttpContext,
next: () => Promise<void>,
Expand Down
4 changes: 2 additions & 2 deletions app/Middleware/Dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { HttpContext } from '@adonisjs/core/http';
import { Config } from '@adonisjs/core/config';
import config from '@adonisjs/core/services/config';

export default class Dashboard {
public async handle({ response }: HttpContext, next: () => Promise<void>) {
if (Config.get('dashboard.enabled') === false) {
if (config.get('dashboard.enabled') === false) {
response.send(
'The user dashboard is disabled on this server\n\nIf you are the server owner, please set IS_DASHBOARD_ENABLED to true to enable the dashboard.',
);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseModel, beforeSave, column, hasMany } from '@adonisjs/lucid/orm';
import hash from '@adonisjs/core/services/hash';
import emitter from '@adonisjs/core/services/emitter';
import moment from 'moment';
import Encryption from '@ioc:Adonis/Core/Encryption';
import { Encryption } from '@adonisjs/core/encryption';
import randtoken from 'rand-token';
import Token from './Token.js';
import Workspace from './Workspace.js';
Expand Down
84 changes: 5 additions & 79 deletions config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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', '') !== '' &&
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions config/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const authConfig: AuthConfig = {
| that time.
|
*/
model: () => import('App/Models/User'),
model: () => import('#app/Models/User'),
},
},
/*
Expand Down Expand Up @@ -163,7 +163,7 @@ const authConfig: AuthConfig = {
| that time.
|
*/
model: () => import('App/Models/User'),
model: () => import('#app/Models/User'),
},
},
/*
Expand Down Expand Up @@ -226,7 +226,7 @@ const authConfig: AuthConfig = {
| that time.
|
*/
model: () => import('App/Models/User'),
model: () => import('#app/Models/User'),
},
},
jwt: {
Expand All @@ -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: {
Expand All @@ -254,7 +253,7 @@ const authConfig: AuthConfig = {
driver: 'lucid',
identifierKey: 'id',
uids: [],
model: () => import('App/Models/User'),
model: () => import('#app/Models/User'),
},
},
},
Expand Down
2 changes: 0 additions & 2 deletions config/bodyparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* file.
*/

import { BodyParserConfig } from '@adonisjs/core/bodyparser';
import { defineConfig } from '@adonisjs/core/bodyparser';

const bodyParserConfig = defineConfig({
Expand Down Expand Up @@ -83,7 +82,6 @@ const bodyParserConfig = defineConfig({
raw: {
encoding: 'utf8',
limit: '1mb',
queryString: {},
types: ['text/*'],
},

Expand Down
2 changes: 1 addition & 1 deletion config/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')!;
8 changes: 2 additions & 6 deletions config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -53,7 +52,6 @@ const databaseConfig = defineConfig({
},
useNullAsDefault: true,
healthCheck: false,
debug: env.get('DB_DEBUG', false),
},

/*
Expand All @@ -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'),
Expand All @@ -80,7 +78,6 @@ const databaseConfig = defineConfig({
naturalSort: true,
},
healthCheck: false,
debug: env.get('DB_DEBUG', false),
},

/*
Expand All @@ -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'),
Expand All @@ -113,7 +110,6 @@ const databaseConfig = defineConfig({
naturalSort: true,
},
healthCheck: false,
debug: env.get('DB_DEBUG', false),
},
},
});
Expand Down
Loading

0 comments on commit c3950f6

Please sign in to comment.