🎉 Initial commit
This commit is contained in:
commit
9b616ce4e3
36 changed files with 9203 additions and 0 deletions
22
.editorconfig
Normal file
22
.editorconfig
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# http://editorconfig.org
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.json]
|
||||||
|
insert_final_newline = unset
|
||||||
|
|
||||||
|
[**.min.js]
|
||||||
|
indent_style = unset
|
||||||
|
insert_final_newline = unset
|
||||||
|
|
||||||
|
[MakeFile]
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
20
.env.example
Normal file
20
.env.example
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TZ=UTC
|
||||||
|
PORT=3333
|
||||||
|
HOST=localhost
|
||||||
|
LOG_LEVEL=info
|
||||||
|
APP_KEY=
|
||||||
|
NODE_ENV=development
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_USER=root
|
||||||
|
DB_PASSWORD=root
|
||||||
|
DB_DATABASE=app
|
||||||
|
LIMITER_STORE=redis
|
||||||
|
DRIVE_DISK=fs
|
||||||
|
SMTP_HOST=
|
||||||
|
SMTP_PORT=
|
||||||
|
REDIS_HOST=127.0.0.1
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_PASSWORD=
|
||||||
|
MAILGUN_API_KEY=
|
||||||
|
MAILGUN_DOMAIN=
|
||||||
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Dependencies and AdonisJS build
|
||||||
|
node_modules
|
||||||
|
build
|
||||||
|
tmp
|
||||||
|
|
||||||
|
# Secrets
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.production.local
|
||||||
|
.env.development.local
|
||||||
|
|
||||||
|
# Frontend assets compiled code
|
||||||
|
public/assets
|
||||||
|
|
||||||
|
# Build tools specific
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
|
||||||
|
# Editors specific
|
||||||
|
.fleet
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# Platform specific
|
||||||
|
.DS_Store
|
||||||
27
ace.js
Normal file
27
ace.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| JavaScript entrypoint for running ace commands
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| DO NOT MODIFY THIS FILE AS IT WILL BE OVERRIDDEN DURING THE BUILD
|
||||||
|
| PROCESS.
|
||||||
|
|
|
||||||
|
| See docs.adonisjs.com/guides/typescript-build-process#creating-production-build
|
||||||
|
|
|
||||||
|
| Since, we cannot run TypeScript source code using "node" binary, we need
|
||||||
|
| a JavaScript entrypoint to run ace commands.
|
||||||
|
|
|
||||||
|
| This file registers the "ts-node/esm" hook with the Node.js module system
|
||||||
|
| and then imports the "bin/console.ts" file.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register hook to process TypeScript files using ts-node
|
||||||
|
*/
|
||||||
|
import 'ts-node-maintained/register/esm'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import ace console entrypoint
|
||||||
|
*/
|
||||||
|
await import('./bin/console.js')
|
||||||
90
adonisrc.ts
Normal file
90
adonisrc.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
import { defineConfig } from '@adonisjs/core/app'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Experimental flags
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The following features will be enabled by default in the next major release
|
||||||
|
| of AdonisJS. You can opt into them today to avoid any breaking changes
|
||||||
|
| during upgrade.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
experimental: {
|
||||||
|
mergeMultipartFieldsAndFiles: true,
|
||||||
|
shutdownInReverseOrder: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Commands
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| List of ace commands to register from packages. The application commands
|
||||||
|
| will be scanned automatically from the "./commands" directory.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
commands: [() => import('@adonisjs/core/commands'), () => import('@adonisjs/lucid/commands'), () => import('@adonisjs/cache/commands'), () => import('@adonisjs/mail/commands')],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Service providers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| List of service providers to import and register when booting the
|
||||||
|
| application
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
providers: [
|
||||||
|
() => import('@adonisjs/core/providers/app_provider'),
|
||||||
|
() => import('@adonisjs/core/providers/hash_provider'),
|
||||||
|
{
|
||||||
|
file: () => import('@adonisjs/core/providers/repl_provider'),
|
||||||
|
environment: ['repl', 'test'],
|
||||||
|
},
|
||||||
|
() => import('@adonisjs/lucid/database_provider'),
|
||||||
|
() => import('@adonisjs/auth/auth_provider'),
|
||||||
|
() => import('@adonisjs/cors/cors_provider'),
|
||||||
|
() => import('@adonisjs/limiter/limiter_provider'),
|
||||||
|
() => import('@adonisjs/cache/cache_provider'),
|
||||||
|
() => import('@adonisjs/drive/drive_provider'),
|
||||||
|
() => import('@adonisjs/mail/mail_provider'),
|
||||||
|
() => import('@adonisjs/redis/redis_provider')
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Preloads
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| List of modules to import before starting the application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
preloads: [() => import('#start/routes'), () => import('#start/kernel')],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Tests
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| List of test suites to organize tests by their type. Feel free to remove
|
||||||
|
| and add additional suites.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
tests: {
|
||||||
|
suites: [
|
||||||
|
{
|
||||||
|
files: ['tests/unit/**/*.spec(.ts|.js)'],
|
||||||
|
name: 'unit',
|
||||||
|
timeout: 2000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['tests/functional/**/*.spec(.ts|.js)'],
|
||||||
|
name: 'functional',
|
||||||
|
timeout: 30000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
forceExit: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
35
app/exceptions/handler.ts
Normal file
35
app/exceptions/handler.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import app from '@adonisjs/core/services/app'
|
||||||
|
import { HttpContext, ExceptionHandler } from '@adonisjs/core/http'
|
||||||
|
|
||||||
|
export default class HttpExceptionHandler extends ExceptionHandler {
|
||||||
|
/**
|
||||||
|
* In debug mode, the exception handler will display verbose errors
|
||||||
|
* with pretty printed stack traces.
|
||||||
|
*/
|
||||||
|
protected debug = !app.inProduction
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status pages are used to display a custom HTML pages for certain error
|
||||||
|
* codes. You might want to enable them in production only, but feel
|
||||||
|
* free to enable them in development as well.
|
||||||
|
*/
|
||||||
|
protected renderStatusPages = app.inProduction
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method is used for handling errors and returning
|
||||||
|
* response to the client
|
||||||
|
*/
|
||||||
|
async handle(error: unknown, ctx: HttpContext) {
|
||||||
|
return super.handle(error, ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method is used to report error to the logging service or
|
||||||
|
* the a third party error monitoring service.
|
||||||
|
*
|
||||||
|
* @note You should not attempt to send a response from this method.
|
||||||
|
*/
|
||||||
|
async report(error: unknown, ctx: HttpContext) {
|
||||||
|
return super.report(error, ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/middleware/auth_middleware.ts
Normal file
25
app/middleware/auth_middleware.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
|
import type { NextFn } from '@adonisjs/core/types/http'
|
||||||
|
import type { Authenticators } from '@adonisjs/auth/types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auth middleware is used authenticate HTTP requests and deny
|
||||||
|
* access to unauthenticated users.
|
||||||
|
*/
|
||||||
|
export default class AuthMiddleware {
|
||||||
|
/**
|
||||||
|
* The URL to redirect to, when authentication fails
|
||||||
|
*/
|
||||||
|
redirectTo = '/login'
|
||||||
|
|
||||||
|
async handle(
|
||||||
|
ctx: HttpContext,
|
||||||
|
next: NextFn,
|
||||||
|
options: {
|
||||||
|
guards?: (keyof Authenticators)[]
|
||||||
|
} = {}
|
||||||
|
) {
|
||||||
|
await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo })
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/middleware/container_bindings_middleware.ts
Normal file
19
app/middleware/container_bindings_middleware.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { Logger } from '@adonisjs/core/logger'
|
||||||
|
import { HttpContext } from '@adonisjs/core/http'
|
||||||
|
import type { NextFn } from '@adonisjs/core/types/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The container bindings middleware binds classes to their request
|
||||||
|
* specific value using the container resolver.
|
||||||
|
*
|
||||||
|
* - We bind "HttpContext" class to the "ctx" object
|
||||||
|
* - And bind "Logger" class to the "ctx.logger" object
|
||||||
|
*/
|
||||||
|
export default class ContainerBindingsMiddleware {
|
||||||
|
handle(ctx: HttpContext, next: NextFn) {
|
||||||
|
ctx.containerResolver.bindValue(HttpContext, ctx)
|
||||||
|
ctx.containerResolver.bindValue(Logger, ctx.logger)
|
||||||
|
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/middleware/guest_middleware.ts
Normal file
31
app/middleware/guest_middleware.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
|
import type { NextFn } from '@adonisjs/core/types/http'
|
||||||
|
import type { Authenticators } from '@adonisjs/auth/types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guest middleware is used to deny access to routes that should
|
||||||
|
* be accessed by unauthenticated users.
|
||||||
|
*
|
||||||
|
* For example, the login page should not be accessible if the user
|
||||||
|
* is already logged-in
|
||||||
|
*/
|
||||||
|
export default class GuestMiddleware {
|
||||||
|
/**
|
||||||
|
* The URL to redirect to when user is logged-in
|
||||||
|
*/
|
||||||
|
redirectTo = '/'
|
||||||
|
|
||||||
|
async handle(
|
||||||
|
ctx: HttpContext,
|
||||||
|
next: NextFn,
|
||||||
|
options: { guards?: (keyof Authenticators)[] } = {}
|
||||||
|
) {
|
||||||
|
for (let guard of options.guards || [ctx.auth.defaultGuard]) {
|
||||||
|
if (await ctx.auth.use(guard).check()) {
|
||||||
|
return ctx.response.redirect(this.redirectTo, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/middleware/silent_auth_middleware.ts
Normal file
19
app/middleware/silent_auth_middleware.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
|
import type { NextFn } from '@adonisjs/core/types/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Silent auth middleware can be used as a global middleware to silent check
|
||||||
|
* if the user is logged-in or not.
|
||||||
|
*
|
||||||
|
* The request continues as usual, even when the user is not logged-in.
|
||||||
|
*/
|
||||||
|
export default class SilentAuthMiddleware {
|
||||||
|
async handle(
|
||||||
|
ctx: HttpContext,
|
||||||
|
next: NextFn,
|
||||||
|
) {
|
||||||
|
await ctx.auth.check()
|
||||||
|
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/models/user.ts
Normal file
30
app/models/user.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import { DateTime } from 'luxon'
|
||||||
|
import hash from '@adonisjs/core/services/hash'
|
||||||
|
import { compose } from '@adonisjs/core/helpers'
|
||||||
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
||||||
|
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
|
||||||
|
|
||||||
|
const AuthFinder = withAuthFinder(() => hash.use('scrypt'), {
|
||||||
|
uids: ['email'],
|
||||||
|
passwordColumnName: 'password',
|
||||||
|
})
|
||||||
|
|
||||||
|
export default class User extends compose(BaseModel, AuthFinder) {
|
||||||
|
@column({ isPrimary: true })
|
||||||
|
declare id: number
|
||||||
|
|
||||||
|
@column()
|
||||||
|
declare fullName: string | null
|
||||||
|
|
||||||
|
@column()
|
||||||
|
declare email: string
|
||||||
|
|
||||||
|
@column({ serializeAs: null })
|
||||||
|
declare password: string
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true })
|
||||||
|
declare createdAt: DateTime
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||||
|
declare updatedAt: DateTime | null
|
||||||
|
}
|
||||||
47
bin/console.ts
Normal file
47
bin/console.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Ace entry point
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The "console.ts" file is the entrypoint for booting the AdonisJS
|
||||||
|
| command-line framework and executing commands.
|
||||||
|
|
|
||||||
|
| Commands do not boot the application, unless the currently running command
|
||||||
|
| has "options.startApp" flag set to true.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'reflect-metadata'
|
||||||
|
import { Ignitor, prettyPrintError } from '@adonisjs/core'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL to the application root. AdonisJS need it to resolve
|
||||||
|
* paths to file and directories for scaffolding commands
|
||||||
|
*/
|
||||||
|
const APP_ROOT = new URL('../', import.meta.url)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The importer is used to import files in context of the
|
||||||
|
* application.
|
||||||
|
*/
|
||||||
|
const IMPORTER = (filePath: string) => {
|
||||||
|
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
||||||
|
return import(new URL(filePath, APP_ROOT).href)
|
||||||
|
}
|
||||||
|
return import(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
new Ignitor(APP_ROOT, { importer: IMPORTER })
|
||||||
|
.tap((app) => {
|
||||||
|
app.booting(async () => {
|
||||||
|
await import('#start/env')
|
||||||
|
})
|
||||||
|
app.listen('SIGTERM', () => app.terminate())
|
||||||
|
app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate())
|
||||||
|
})
|
||||||
|
.ace()
|
||||||
|
.handle(process.argv.splice(2))
|
||||||
|
.catch((error) => {
|
||||||
|
process.exitCode = 1
|
||||||
|
prettyPrintError(error)
|
||||||
|
})
|
||||||
45
bin/server.ts
Normal file
45
bin/server.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| HTTP server entrypoint
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The "server.ts" file is the entrypoint for starting the AdonisJS HTTP
|
||||||
|
| server. Either you can run this file directly or use the "serve"
|
||||||
|
| command to run this file and monitor file changes
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'reflect-metadata'
|
||||||
|
import { Ignitor, prettyPrintError } from '@adonisjs/core'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL to the application root. AdonisJS need it to resolve
|
||||||
|
* paths to file and directories for scaffolding commands
|
||||||
|
*/
|
||||||
|
const APP_ROOT = new URL('../', import.meta.url)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The importer is used to import files in context of the
|
||||||
|
* application.
|
||||||
|
*/
|
||||||
|
const IMPORTER = (filePath: string) => {
|
||||||
|
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
||||||
|
return import(new URL(filePath, APP_ROOT).href)
|
||||||
|
}
|
||||||
|
return import(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
new Ignitor(APP_ROOT, { importer: IMPORTER })
|
||||||
|
.tap((app) => {
|
||||||
|
app.booting(async () => {
|
||||||
|
await import('#start/env')
|
||||||
|
})
|
||||||
|
app.listen('SIGTERM', () => app.terminate())
|
||||||
|
app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate())
|
||||||
|
})
|
||||||
|
.httpServer()
|
||||||
|
.start()
|
||||||
|
.catch((error) => {
|
||||||
|
process.exitCode = 1
|
||||||
|
prettyPrintError(error)
|
||||||
|
})
|
||||||
62
bin/test.ts
Normal file
62
bin/test.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Test runner entrypoint
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The "test.ts" file is the entrypoint for running tests using Japa.
|
||||||
|
|
|
||||||
|
| Either you can run this file directly or use the "test"
|
||||||
|
| command to run this file and monitor file changes.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
process.env.NODE_ENV = 'test'
|
||||||
|
|
||||||
|
import 'reflect-metadata'
|
||||||
|
import { Ignitor, prettyPrintError } from '@adonisjs/core'
|
||||||
|
import { configure, processCLIArgs, run } from '@japa/runner'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL to the application root. AdonisJS need it to resolve
|
||||||
|
* paths to file and directories for scaffolding commands
|
||||||
|
*/
|
||||||
|
const APP_ROOT = new URL('../', import.meta.url)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The importer is used to import files in context of the
|
||||||
|
* application.
|
||||||
|
*/
|
||||||
|
const IMPORTER = (filePath: string) => {
|
||||||
|
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
||||||
|
return import(new URL(filePath, APP_ROOT).href)
|
||||||
|
}
|
||||||
|
return import(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
new Ignitor(APP_ROOT, { importer: IMPORTER })
|
||||||
|
.tap((app) => {
|
||||||
|
app.booting(async () => {
|
||||||
|
await import('#start/env')
|
||||||
|
})
|
||||||
|
app.listen('SIGTERM', () => app.terminate())
|
||||||
|
app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate())
|
||||||
|
})
|
||||||
|
.testRunner()
|
||||||
|
.configure(async (app) => {
|
||||||
|
const { runnerHooks, ...config } = await import('../tests/bootstrap.js')
|
||||||
|
|
||||||
|
processCLIArgs(process.argv.splice(2))
|
||||||
|
configure({
|
||||||
|
...app.rcFile.tests,
|
||||||
|
...config,
|
||||||
|
...{
|
||||||
|
setup: runnerHooks.setup,
|
||||||
|
teardown: runnerHooks.teardown.concat([() => app.terminate()]),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.run(() => run())
|
||||||
|
.catch((error) => {
|
||||||
|
process.exitCode = 1
|
||||||
|
prettyPrintError(error)
|
||||||
|
})
|
||||||
40
config/app.ts
Normal file
40
config/app.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import app from '@adonisjs/core/services/app'
|
||||||
|
import { Secret } from '@adonisjs/core/helpers'
|
||||||
|
import { defineConfig } from '@adonisjs/core/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The app key is used for encrypting cookies, generating signed URLs,
|
||||||
|
* and by the "encryption" module.
|
||||||
|
*
|
||||||
|
* The encryption module will fail to decrypt data if the key is lost or
|
||||||
|
* changed. Therefore it is recommended to keep the app key secure.
|
||||||
|
*/
|
||||||
|
export const appKey = new Secret(env.get('APP_KEY'))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration settings used by the HTTP server
|
||||||
|
*/
|
||||||
|
export const http = defineConfig({
|
||||||
|
generateRequestId: true,
|
||||||
|
allowMethodSpoofing: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enabling async local storage will let you access HTTP context
|
||||||
|
* from anywhere inside your application.
|
||||||
|
*/
|
||||||
|
useAsyncLocalStorage: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage cookies configuration. The settings for the session id cookie are
|
||||||
|
* defined inside the "config/session.ts" file.
|
||||||
|
*/
|
||||||
|
cookie: {
|
||||||
|
domain: '',
|
||||||
|
path: '/',
|
||||||
|
maxAge: '2h',
|
||||||
|
httpOnly: true,
|
||||||
|
secure: app.inProduction,
|
||||||
|
sameSite: 'lax',
|
||||||
|
},
|
||||||
|
})
|
||||||
28
config/auth.ts
Normal file
28
config/auth.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { defineConfig } from '@adonisjs/auth'
|
||||||
|
import { sessionGuard, sessionUserProvider } from '@adonisjs/auth/session'
|
||||||
|
import type { InferAuthenticators, InferAuthEvents, Authenticators } from '@adonisjs/auth/types'
|
||||||
|
|
||||||
|
const authConfig = defineConfig({
|
||||||
|
default: 'web',
|
||||||
|
guards: {
|
||||||
|
web: sessionGuard({
|
||||||
|
useRememberMeTokens: false,
|
||||||
|
provider: sessionUserProvider({
|
||||||
|
model: () => import('#models/user')
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default authConfig
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inferring types from the configured auth
|
||||||
|
* guards.
|
||||||
|
*/
|
||||||
|
declare module '@adonisjs/auth/types' {
|
||||||
|
export interface Authenticators extends InferAuthenticators<typeof authConfig> {}
|
||||||
|
}
|
||||||
|
declare module '@adonisjs/core/types' {
|
||||||
|
interface EventsList extends InferAuthEvents<Authenticators> {}
|
||||||
|
}
|
||||||
55
config/bodyparser.ts
Normal file
55
config/bodyparser.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
import { defineConfig } from '@adonisjs/core/bodyparser'
|
||||||
|
|
||||||
|
const bodyParserConfig = defineConfig({
|
||||||
|
/**
|
||||||
|
* The bodyparser middleware will parse the request body
|
||||||
|
* for the following HTTP methods.
|
||||||
|
*/
|
||||||
|
allowedMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config for the "application/x-www-form-urlencoded"
|
||||||
|
* content-type parser
|
||||||
|
*/
|
||||||
|
form: {
|
||||||
|
convertEmptyStringsToNull: true,
|
||||||
|
types: ['application/x-www-form-urlencoded'],
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config for the JSON parser
|
||||||
|
*/
|
||||||
|
json: {
|
||||||
|
convertEmptyStringsToNull: true,
|
||||||
|
types: [
|
||||||
|
'application/json',
|
||||||
|
'application/json-patch+json',
|
||||||
|
'application/vnd.api+json',
|
||||||
|
'application/csp-report',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config for the "multipart/form-data" content-type parser.
|
||||||
|
* File uploads are handled by the multipart parser.
|
||||||
|
*/
|
||||||
|
multipart: {
|
||||||
|
/**
|
||||||
|
* Enabling auto process allows bodyparser middleware to
|
||||||
|
* move all uploaded files inside the tmp folder of your
|
||||||
|
* operating system
|
||||||
|
*/
|
||||||
|
autoProcess: true,
|
||||||
|
convertEmptyStringsToNull: true,
|
||||||
|
processManually: [],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum limit of data to parse including all files
|
||||||
|
* and fields
|
||||||
|
*/
|
||||||
|
limit: '20mb',
|
||||||
|
types: ['multipart/form-data'],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default bodyParserConfig
|
||||||
24
config/cache.ts
Normal file
24
config/cache.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import { defineConfig, store, drivers } from '@adonisjs/cache'
|
||||||
|
|
||||||
|
const cacheConfig = defineConfig({
|
||||||
|
default: 'default',
|
||||||
|
|
||||||
|
stores: {
|
||||||
|
memoryOnly: store().useL1Layer(drivers.memory()),
|
||||||
|
|
||||||
|
default: store()
|
||||||
|
.useL1Layer(drivers.memory())
|
||||||
|
|
||||||
|
.useL2Layer(drivers.redis({
|
||||||
|
connectionName: 'main',
|
||||||
|
}))
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default cacheConfig
|
||||||
|
|
||||||
|
declare module '@adonisjs/cache/types' {
|
||||||
|
interface CacheStores extends InferStores<typeof cacheConfig> {}
|
||||||
|
}
|
||||||
19
config/cors.ts
Normal file
19
config/cors.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { defineConfig } from '@adonisjs/cors'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration options to tweak the CORS policy. The following
|
||||||
|
* options are documented on the official documentation website.
|
||||||
|
*
|
||||||
|
* https://docs.adonisjs.com/guides/security/cors
|
||||||
|
*/
|
||||||
|
const corsConfig = defineConfig({
|
||||||
|
enabled: true,
|
||||||
|
origin: true,
|
||||||
|
methods: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'],
|
||||||
|
headers: true,
|
||||||
|
exposeHeaders: [],
|
||||||
|
credentials: true,
|
||||||
|
maxAge: 90,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default corsConfig
|
||||||
24
config/database.ts
Normal file
24
config/database.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import { defineConfig } from '@adonisjs/lucid'
|
||||||
|
|
||||||
|
const dbConfig = defineConfig({
|
||||||
|
connection: 'postgres',
|
||||||
|
connections: {
|
||||||
|
postgres: {
|
||||||
|
client: 'pg',
|
||||||
|
connection: {
|
||||||
|
host: env.get('DB_HOST'),
|
||||||
|
port: env.get('DB_PORT'),
|
||||||
|
user: env.get('DB_USER'),
|
||||||
|
password: env.get('DB_PASSWORD'),
|
||||||
|
database: env.get('DB_DATABASE'),
|
||||||
|
},
|
||||||
|
migrations: {
|
||||||
|
naturalSort: true,
|
||||||
|
paths: ['database/migrations'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default dbConfig
|
||||||
26
config/drive.ts
Normal file
26
config/drive.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import app from '@adonisjs/core/services/app'
|
||||||
|
import { defineConfig, services } from '@adonisjs/drive'
|
||||||
|
|
||||||
|
const driveConfig = defineConfig({
|
||||||
|
default: env.get('DRIVE_DISK'),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The services object can be used to configure multiple file system
|
||||||
|
* services each using the same or a different driver.
|
||||||
|
*/
|
||||||
|
services: {
|
||||||
|
fs: services.fs({
|
||||||
|
location: app.makePath('storage'),
|
||||||
|
serveFiles: true,
|
||||||
|
routeBasePath: '/uploads',
|
||||||
|
visibility: 'public',
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default driveConfig
|
||||||
|
|
||||||
|
declare module '@adonisjs/drive/types' {
|
||||||
|
export interface DriveDisks extends InferDriveDisks<typeof driveConfig> {}
|
||||||
|
}
|
||||||
24
config/hash.ts
Normal file
24
config/hash.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { defineConfig, drivers } from '@adonisjs/core/hash'
|
||||||
|
|
||||||
|
const hashConfig = defineConfig({
|
||||||
|
default: 'scrypt',
|
||||||
|
|
||||||
|
list: {
|
||||||
|
scrypt: drivers.scrypt({
|
||||||
|
cost: 16384,
|
||||||
|
blockSize: 8,
|
||||||
|
parallelization: 1,
|
||||||
|
maxMemory: 33554432,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default hashConfig
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inferring types for the list of hashers you have configured
|
||||||
|
* in your application.
|
||||||
|
*/
|
||||||
|
declare module '@adonisjs/core/types' {
|
||||||
|
export interface HashersList extends InferHashers<typeof hashConfig> {}
|
||||||
|
}
|
||||||
30
config/limiter.ts
Normal file
30
config/limiter.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import { defineConfig, stores } from '@adonisjs/limiter'
|
||||||
|
|
||||||
|
const limiterConfig = defineConfig({
|
||||||
|
default: env.get('LIMITER_STORE'),
|
||||||
|
stores: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis store to save rate limiting data inside a
|
||||||
|
* redis database.
|
||||||
|
*
|
||||||
|
* It is recommended to use a separate database for
|
||||||
|
* the limiter connection.
|
||||||
|
*/
|
||||||
|
redis: stores.redis({}),
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memory store could be used during
|
||||||
|
* testing
|
||||||
|
*/
|
||||||
|
memory: stores.memory({})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default limiterConfig
|
||||||
|
|
||||||
|
declare module '@adonisjs/limiter/types' {
|
||||||
|
export interface LimitersList extends InferLimiters<typeof limiterConfig> {}
|
||||||
|
}
|
||||||
35
config/logger.ts
Normal file
35
config/logger.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import app from '@adonisjs/core/services/app'
|
||||||
|
import { defineConfig, targets } from '@adonisjs/core/logger'
|
||||||
|
|
||||||
|
const loggerConfig = defineConfig({
|
||||||
|
default: 'app',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The loggers object can be used to define multiple loggers.
|
||||||
|
* By default, we configure only one logger (named "app").
|
||||||
|
*/
|
||||||
|
loggers: {
|
||||||
|
app: {
|
||||||
|
enabled: true,
|
||||||
|
name: env.get('APP_NAME'),
|
||||||
|
level: env.get('LOG_LEVEL'),
|
||||||
|
transport: {
|
||||||
|
targets: targets()
|
||||||
|
.pushIf(!app.inProduction, targets.pretty())
|
||||||
|
.pushIf(app.inProduction, targets.file({ destination: 1 }))
|
||||||
|
.toArray(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default loggerConfig
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inferring types for the list of loggers you have configured
|
||||||
|
* in your application.
|
||||||
|
*/
|
||||||
|
declare module '@adonisjs/core/types' {
|
||||||
|
export interface LoggersList extends InferLoggers<typeof loggerConfig> {}
|
||||||
|
}
|
||||||
26
config/mail.ts
Normal file
26
config/mail.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import { defineConfig, transports } from '@adonisjs/mail'
|
||||||
|
|
||||||
|
const mailConfig = defineConfig({
|
||||||
|
default: 'mailgun',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mailers object can be used to configure multiple mailers
|
||||||
|
* each using a different transport or same transport with different
|
||||||
|
* options.
|
||||||
|
*/
|
||||||
|
mailers: {
|
||||||
|
mailgun: transports.mailgun({
|
||||||
|
key: env.get('MAILGUN_API_KEY'),
|
||||||
|
baseUrl: 'https://api.mailgun.net/v3',
|
||||||
|
domain: env.get('MAILGUN_DOMAIN'),
|
||||||
|
}),
|
||||||
|
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default mailConfig
|
||||||
|
|
||||||
|
declare module '@adonisjs/mail/types' {
|
||||||
|
export interface MailersList extends InferMailers<typeof mailConfig> {}
|
||||||
|
}
|
||||||
36
config/redis.ts
Normal file
36
config/redis.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import env from '#start/env'
|
||||||
|
import { defineConfig } from '@adonisjs/redis'
|
||||||
|
import { InferConnections } from '@adonisjs/redis/types'
|
||||||
|
|
||||||
|
const redisConfig = defineConfig({
|
||||||
|
connection: 'main',
|
||||||
|
|
||||||
|
connections: {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| The default connection
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The main connection you want to use to execute redis commands. The same
|
||||||
|
| connection will be used by the session provider, if you rely on the
|
||||||
|
| redis driver.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
main: {
|
||||||
|
host: env.get('REDIS_HOST'),
|
||||||
|
port: env.get('REDIS_PORT'),
|
||||||
|
password: env.get('REDIS_PASSWORD', ''),
|
||||||
|
db: 0,
|
||||||
|
keyPrefix: '',
|
||||||
|
retryStrategy(times) {
|
||||||
|
return times > 10 ? null : times * 50
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default redisConfig
|
||||||
|
|
||||||
|
declare module '@adonisjs/redis/types' {
|
||||||
|
export interface RedisConnections extends InferConnections<typeof redisConfig> {}
|
||||||
|
}
|
||||||
21
database/migrations/1747564644339_create_users_table.ts
Normal file
21
database/migrations/1747564644339_create_users_table.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { BaseSchema } from '@adonisjs/lucid/schema'
|
||||||
|
|
||||||
|
export default class extends BaseSchema {
|
||||||
|
protected tableName = 'users'
|
||||||
|
|
||||||
|
async up() {
|
||||||
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
|
table.increments('id').notNullable()
|
||||||
|
table.string('full_name').nullable()
|
||||||
|
table.string('email', 254).notNullable().unique()
|
||||||
|
table.string('password').notNullable()
|
||||||
|
|
||||||
|
table.timestamp('created_at').notNullable()
|
||||||
|
table.timestamp('updated_at').nullable()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async down() {
|
||||||
|
this.schema.dropTable(this.tableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
2
eslint.config.js
Normal file
2
eslint.config.js
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
import { configApp } from '@adonisjs/eslint-config'
|
||||||
|
export default configApp()
|
||||||
8069
package-lock.json
generated
Normal file
8069
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
76
package.json
Normal file
76
package.json
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
{
|
||||||
|
"name": "api",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"license": "UNLICENSED",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node bin/server.js",
|
||||||
|
"build": "node ace build",
|
||||||
|
"dev": "node ace serve --hmr",
|
||||||
|
"test": "node ace test",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"imports": {
|
||||||
|
"#controllers/*": "./app/controllers/*.js",
|
||||||
|
"#exceptions/*": "./app/exceptions/*.js",
|
||||||
|
"#models/*": "./app/models/*.js",
|
||||||
|
"#mails/*": "./app/mails/*.js",
|
||||||
|
"#services/*": "./app/services/*.js",
|
||||||
|
"#listeners/*": "./app/listeners/*.js",
|
||||||
|
"#events/*": "./app/events/*.js",
|
||||||
|
"#middleware/*": "./app/middleware/*.js",
|
||||||
|
"#validators/*": "./app/validators/*.js",
|
||||||
|
"#providers/*": "./providers/*.js",
|
||||||
|
"#policies/*": "./app/policies/*.js",
|
||||||
|
"#abilities/*": "./app/abilities/*.js",
|
||||||
|
"#database/*": "./database/*.js",
|
||||||
|
"#start/*": "./start/*.js",
|
||||||
|
"#tests/*": "./tests/*.js",
|
||||||
|
"#config/*": "./config/*.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@adonisjs/assembler": "^7.8.2",
|
||||||
|
"@adonisjs/eslint-config": "^2.0.0",
|
||||||
|
"@adonisjs/prettier-config": "^1.4.4",
|
||||||
|
"@adonisjs/tsconfig": "^1.4.0",
|
||||||
|
"@japa/assert": "^4.0.1",
|
||||||
|
"@japa/plugin-adonisjs": "^4.0.0",
|
||||||
|
"@japa/runner": "^4.2.0",
|
||||||
|
"@swc/core": "1.11.24",
|
||||||
|
"@types/luxon": "^3.6.2",
|
||||||
|
"@types/node": "^22.15.18",
|
||||||
|
"eslint": "^9.26.0",
|
||||||
|
"hot-hook": "^0.4.0",
|
||||||
|
"pino-pretty": "^13.0.0",
|
||||||
|
"prettier": "^3.5.3",
|
||||||
|
"ts-node-maintained": "^10.9.5",
|
||||||
|
"typescript": "~5.8"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@adonisjs/auth": "^9.4.0",
|
||||||
|
"@adonisjs/cache": "^1.1.3",
|
||||||
|
"@adonisjs/core": "^6.18.0",
|
||||||
|
"@adonisjs/cors": "^2.2.1",
|
||||||
|
"@adonisjs/drive": "^3.4.1",
|
||||||
|
"@adonisjs/limiter": "^2.4.0",
|
||||||
|
"@adonisjs/lucid": "^21.6.1",
|
||||||
|
"@adonisjs/mail": "^9.2.2",
|
||||||
|
"@adonisjs/redis": "^9.2.0",
|
||||||
|
"luxon": "^3.6.1",
|
||||||
|
"pg": "^8.16.0",
|
||||||
|
"reflect-metadata": "^0.2.2"
|
||||||
|
},
|
||||||
|
"hotHook": {
|
||||||
|
"boundaries": [
|
||||||
|
"./app/controllers/**/*.ts",
|
||||||
|
"./app/middleware/*.ts"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "@adonisjs/eslint-config/app"
|
||||||
|
},
|
||||||
|
"prettier": "@adonisjs/prettier-config"
|
||||||
|
}
|
||||||
59
start/env.ts
Normal file
59
start/env.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Environment variables service
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The `Env.create` method creates an instance of the Env service. The
|
||||||
|
| service validates the environment variables and also cast values
|
||||||
|
| to JavaScript data types.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Env } from '@adonisjs/core/env'
|
||||||
|
|
||||||
|
export default await Env.create(new URL('../', import.meta.url), {
|
||||||
|
NODE_ENV: Env.schema.enum(['development', 'production', 'test'] as const),
|
||||||
|
PORT: Env.schema.number(),
|
||||||
|
APP_KEY: Env.schema.string(),
|
||||||
|
HOST: Env.schema.string({ format: 'host' }),
|
||||||
|
LOG_LEVEL: Env.schema.string(),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
|
| Variables for configuring database connection
|
||||||
|
|----------------------------------------------------------
|
||||||
|
*/
|
||||||
|
DB_HOST: Env.schema.string({ format: 'host' }),
|
||||||
|
DB_PORT: Env.schema.number(),
|
||||||
|
DB_USER: Env.schema.string(),
|
||||||
|
DB_PASSWORD: Env.schema.string.optional(),
|
||||||
|
DB_DATABASE: Env.schema.string(),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
|
| Variables for configuring the limiter package
|
||||||
|
|----------------------------------------------------------
|
||||||
|
*/
|
||||||
|
LIMITER_STORE: Env.schema.enum(['redis', 'memory'] as const),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
|
| Variables for configuring the drive package
|
||||||
|
|----------------------------------------------------------
|
||||||
|
*/
|
||||||
|
DRIVE_DISK: Env.schema.enum(['fs'] as const),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
|
| Variables for configuring the mail package
|
||||||
|
|----------------------------------------------------------
|
||||||
|
*/
|
||||||
|
SMTP_HOST: Env.schema.string(),
|
||||||
|
SMTP_PORT: Env.schema.string(),
|
||||||
|
|
||||||
|
REDIS_HOST: Env.schema.string({ format: 'host' }),
|
||||||
|
REDIS_PORT: Env.schema.number(),
|
||||||
|
REDIS_PASSWORD: Env.schema.string.optional(),
|
||||||
|
MAILGUN_API_KEY: Env.schema.string(),
|
||||||
|
MAILGUN_DOMAIN: Env.schema.string()
|
||||||
|
})
|
||||||
40
start/kernel.ts
Normal file
40
start/kernel.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| HTTP kernel file
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The HTTP kernel file is used to register the middleware with the server
|
||||||
|
| or the router.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import router from '@adonisjs/core/services/router'
|
||||||
|
import server from '@adonisjs/core/services/server'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error handler is used to convert an exception
|
||||||
|
* to a HTTP response.
|
||||||
|
*/
|
||||||
|
server.errorHandler(() => import('#exceptions/handler'))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The server middleware stack runs middleware on all the HTTP
|
||||||
|
* requests, even if there is no route registered for
|
||||||
|
* the request URL.
|
||||||
|
*/
|
||||||
|
server.use([() => import('#middleware/container_bindings_middleware'), () => import('@adonisjs/cors/cors_middleware')])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The router middleware stack runs middleware on all the HTTP
|
||||||
|
* requests with a registered route.
|
||||||
|
*/
|
||||||
|
router.use([() => import('@adonisjs/core/bodyparser_middleware'), () => import('@adonisjs/auth/initialize_auth_middleware')])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Named middleware collection must be explicitly assigned to
|
||||||
|
* the routes or the routes group.
|
||||||
|
*/
|
||||||
|
export const middleware = router.named({
|
||||||
|
guest: () => import('#middleware/guest_middleware'),
|
||||||
|
auth: () => import('#middleware/auth_middleware')
|
||||||
|
})
|
||||||
16
start/limiter.ts
Normal file
16
start/limiter.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Define HTTP limiters
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The "limiter.define" method creates an HTTP middleware to apply rate
|
||||||
|
| limits on a route or a group of routes. Feel free to define as many
|
||||||
|
| throttle middleware as needed.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import limiter from '@adonisjs/limiter/services/main'
|
||||||
|
|
||||||
|
export const throttle = limiter.define('global', () => {
|
||||||
|
return limiter.allowRequests(10).every('1 minute')
|
||||||
|
})
|
||||||
12
start/routes.ts
Normal file
12
start/routes.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Routes file
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The routes file is used for defining the HTTP routes.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import router from '@adonisjs/core/services/router'
|
||||||
|
|
||||||
|
router.get('/', async () => 'It works!')
|
||||||
37
tests/bootstrap.ts
Normal file
37
tests/bootstrap.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { assert } from '@japa/assert'
|
||||||
|
import app from '@adonisjs/core/services/app'
|
||||||
|
import type { Config } from '@japa/runner/types'
|
||||||
|
import { pluginAdonisJS } from '@japa/plugin-adonisjs'
|
||||||
|
import testUtils from '@adonisjs/core/services/test_utils'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is imported by the "bin/test.ts" entrypoint file
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure Japa plugins in the plugins array.
|
||||||
|
* Learn more - https://japa.dev/docs/runner-config#plugins-optional
|
||||||
|
*/
|
||||||
|
export const plugins: Config['plugins'] = [assert(), pluginAdonisJS(app)]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure lifecycle function to run before and after all the
|
||||||
|
* tests.
|
||||||
|
*
|
||||||
|
* The setup functions are executed before all the tests
|
||||||
|
* The teardown functions are executed after all the tests
|
||||||
|
*/
|
||||||
|
export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = {
|
||||||
|
setup: [],
|
||||||
|
teardown: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure suites by tapping into the test suite instance.
|
||||||
|
* Learn more - https://japa.dev/docs/test-suites#lifecycle-hooks
|
||||||
|
*/
|
||||||
|
export const configureSuite: Config['configureSuite'] = (suite) => {
|
||||||
|
if (['browser', 'functional', 'e2e'].includes(suite.name)) {
|
||||||
|
return suite.setup(() => testUtils.httpServer().start())
|
||||||
|
}
|
||||||
|
}
|
||||||
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"extends": "@adonisjs/tsconfig/tsconfig.app.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "./",
|
||||||
|
"outDir": "./build"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue