init
This commit is contained in:
@@ -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
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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=database
|
||||||
+25
@@ -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
|
||||||
@@ -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')
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
import { defineConfig } from '@adonisjs/core/app'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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')],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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/core/providers/vinejs_provider'),
|
||||||
|
() => import('@adonisjs/cors/cors_provider'),
|
||||||
|
() => import('@adonisjs/lucid/database_provider'),
|
||||||
|
() => import('@adonisjs/auth/auth_provider'),
|
||||||
|
() => import('@adonisjs/limiter/limiter_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,
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
|
import { registerValidator, loginValidator } from '#validators/auth'
|
||||||
|
import User from '#models/user'
|
||||||
|
import logger from '@adonisjs/core/services/logger'
|
||||||
|
|
||||||
|
export default class AuthController {
|
||||||
|
|
||||||
|
async register({ request }: HttpContext) {
|
||||||
|
try {
|
||||||
|
const data = await request.validateUsing(registerValidator)
|
||||||
|
const user = await User.create(data)
|
||||||
|
logger.info('User registered: %s', user.fullName, user.email, request.ip())
|
||||||
|
return User.accessTokens.create(user)
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
logger.error('Registration failed: %s',error)
|
||||||
|
throw(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async login({ request }: HttpContext) {
|
||||||
|
try {
|
||||||
|
const { email, password } = await request.validateUsing(loginValidator)
|
||||||
|
const user = await User.verifyCredentials(email, password)
|
||||||
|
logger.info('User logged in: %s', email)
|
||||||
|
return User.accessTokens.create(user)
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
logger.error('Login failed: %s',error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async logout({ auth }: HttpContext) {
|
||||||
|
const user = auth.user!
|
||||||
|
logger.info('User logout: %s', auth.getUserOrFail().email)
|
||||||
|
try {
|
||||||
|
await User.accessTokens.delete(user, user.currentAccessToken.identifier)
|
||||||
|
return { message: 'User logged out' }
|
||||||
|
}
|
||||||
|
catch(error){
|
||||||
|
logger.error('Logout failed: %s',error)
|
||||||
|
throw(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async me({ auth }: HttpContext) {
|
||||||
|
if (await auth.check()) {
|
||||||
|
return { user: auth.user }
|
||||||
|
} else {
|
||||||
|
await User.accessTokens.delete(auth.user!, auth.user!.currentAccessToken.identifier)
|
||||||
|
return { message: 'Unauthorized' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
|
import type { NextFn } from '@adonisjs/core/types/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updating the "Accept" header to always accept "application/json" response
|
||||||
|
* from the server. This will force the internals of the framework like
|
||||||
|
* validator errors or auth errors to return a JSON response.
|
||||||
|
*/
|
||||||
|
export default class ForceJsonResponseMiddleware {
|
||||||
|
async handle({ request }: HttpContext, next: NextFn) {
|
||||||
|
const headers = request.headers()
|
||||||
|
headers.accept = 'application/json'
|
||||||
|
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { DateTime } from 'luxon'
|
||||||
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
||||||
|
|
||||||
|
export default class RateLimit extends BaseModel {
|
||||||
|
@column({ isPrimary: true })
|
||||||
|
declare id: number
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true })
|
||||||
|
declare createdAt: DateTime
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||||
|
declare updatedAt: DateTime
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { DateTime } from 'luxon'
|
||||||
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
||||||
|
|
||||||
|
export default class RestaurantMenu extends BaseModel {
|
||||||
|
@column({ isPrimary: true })
|
||||||
|
declare id: number
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true })
|
||||||
|
declare createdAt: DateTime
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||||
|
declare updatedAt: DateTime
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { DateTime } from 'luxon'
|
||||||
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
||||||
|
|
||||||
|
export default class RestaurantMenuItem extends BaseModel {
|
||||||
|
@column({ isPrimary: true })
|
||||||
|
declare id: number
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true })
|
||||||
|
declare createdAt: DateTime
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||||
|
declare updatedAt: DateTime
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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'
|
||||||
|
import { DbAccessTokensProvider } from '@adonisjs/auth/access_tokens'
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
static accessTokens = DbAccessTokensProvider.forModel(User, {
|
||||||
|
expiresIn: '2 days',
|
||||||
|
prefix: 'tok_',
|
||||||
|
table: 'auth_access_tokens',
|
||||||
|
type: 'auth_token',
|
||||||
|
tokenSecretLength: 40,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import vine from '@vinejs/vine'
|
||||||
|
|
||||||
|
const password = vine.string().minLength(8)
|
||||||
|
|
||||||
|
export const registerValidator = vine.compile(
|
||||||
|
vine.object({
|
||||||
|
email: vine
|
||||||
|
.string()
|
||||||
|
.email()
|
||||||
|
.normalizeEmail()
|
||||||
|
.unique(async (db, value) => {
|
||||||
|
const match = await db.from('users').select('id').where('email', value).first()
|
||||||
|
return !match
|
||||||
|
}),
|
||||||
|
password,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
export const loginValidator = vine.compile(
|
||||||
|
vine.object({
|
||||||
|
email: vine.string().email().normalizeEmail(),
|
||||||
|
password,
|
||||||
|
})
|
||||||
|
)
|
||||||
@@ -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)
|
||||||
|
})
|
||||||
@@ -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
@@ -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)
|
||||||
|
})
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
services:
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
restart: always
|
||||||
|
# set shared memory limit when using docker compose
|
||||||
|
shm_size: 128mb
|
||||||
|
# or set shared memory limit when deploy via swarm stack
|
||||||
|
#volumes:
|
||||||
|
# - type: tmpfs
|
||||||
|
# target: /dev/shm
|
||||||
|
# tmpfs:
|
||||||
|
# size: 134217728 # 128*2^20 bytes = 128Mb
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: Paprika_2025
|
||||||
|
POSTGRES_USER: paprika
|
||||||
|
POSTGRES_DB: paprika
|
||||||
|
adminer:
|
||||||
|
image: adminer
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
@@ -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: true,
|
||||||
|
sameSite: 'lax',
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { defineConfig } from '@adonisjs/auth'
|
||||||
|
import { tokensGuard, tokensUserProvider } from '@adonisjs/auth/access_tokens'
|
||||||
|
import type { InferAuthenticators, InferAuthEvents, Authenticators } from '@adonisjs/auth/types'
|
||||||
|
|
||||||
|
const authConfig = defineConfig({
|
||||||
|
default: 'api',
|
||||||
|
guards: {
|
||||||
|
api: tokensGuard({
|
||||||
|
provider: tokensUserProvider({
|
||||||
|
tokens: 'accessTokens',
|
||||||
|
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> {}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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> {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import env from '#start/env'
|
||||||
|
import { defineConfig, stores } from '@adonisjs/limiter'
|
||||||
|
|
||||||
|
const limiterConfig = defineConfig({
|
||||||
|
default: env.get('LIMITER_STORE'),
|
||||||
|
stores: {
|
||||||
|
/**
|
||||||
|
* Database store to save rate limiting data inside a
|
||||||
|
* MYSQL or PostgreSQL database.
|
||||||
|
*/
|
||||||
|
database: stores.database({
|
||||||
|
connectionName: 'postgres',
|
||||||
|
dbName:'paprika',
|
||||||
|
tableName: 'rate_limits',
|
||||||
|
clearExpiredByTimeout: false
|
||||||
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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> {}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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> {}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { BaseSchema } from '@adonisjs/lucid/schema'
|
||||||
|
|
||||||
|
export default class extends BaseSchema {
|
||||||
|
protected tableName = 'auth_access_tokens'
|
||||||
|
|
||||||
|
async up() {
|
||||||
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
|
table.increments('id')
|
||||||
|
table
|
||||||
|
.integer('tokenable_id')
|
||||||
|
.notNullable()
|
||||||
|
.unsigned()
|
||||||
|
.references('id')
|
||||||
|
.inTable('users')
|
||||||
|
.onDelete('CASCADE')
|
||||||
|
|
||||||
|
table.string('type').notNullable()
|
||||||
|
table.string('name').nullable()
|
||||||
|
table.string('hash').notNullable()
|
||||||
|
table.text('abilities').notNullable()
|
||||||
|
table.timestamp('created_at')
|
||||||
|
table.timestamp('updated_at')
|
||||||
|
table.timestamp('last_used_at').nullable()
|
||||||
|
table.timestamp('expires_at').nullable()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async down() {
|
||||||
|
this.schema.dropTable(this.tableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { BaseSchema } from '@adonisjs/lucid/schema'
|
||||||
|
|
||||||
|
export default class extends BaseSchema {
|
||||||
|
protected tableName = 'dbs'
|
||||||
|
|
||||||
|
async up() {
|
||||||
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
|
table.increments('id')
|
||||||
|
|
||||||
|
table.timestamp('created_at')
|
||||||
|
table.timestamp('updated_at')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async down() {
|
||||||
|
this.schema.dropTable(this.tableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { BaseSchema } from '@adonisjs/lucid/schema'
|
||||||
|
|
||||||
|
export default class extends BaseSchema {
|
||||||
|
protected tableName = 'rate_limits'
|
||||||
|
|
||||||
|
async up() {
|
||||||
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
|
table.string('key', 255).notNullable().primary()
|
||||||
|
table.integer('points', 9).notNullable().defaultTo(0)
|
||||||
|
table.bigint('expire').unsigned()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async down() {
|
||||||
|
this.schema.dropTable(this.tableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import { configApp } from '@adonisjs/eslint-config'
|
||||||
|
export default configApp()
|
||||||
Generated
+7647
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
"name": "paprika-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.0",
|
||||||
|
"@adonisjs/tsconfig": "^1.4.0",
|
||||||
|
"@japa/api-client": "^3.0.3",
|
||||||
|
"@japa/assert": "^4.0.1",
|
||||||
|
"@japa/plugin-adonisjs": "^4.0.0",
|
||||||
|
"@japa/runner": "^4.2.0",
|
||||||
|
"@swc/core": "1.10.7",
|
||||||
|
"@types/luxon": "^3.6.2",
|
||||||
|
"@types/node": "^22.13.2",
|
||||||
|
"eslint": "^9.20.1",
|
||||||
|
"hot-hook": "^0.4.0",
|
||||||
|
"pino-pretty": "^13.0.0",
|
||||||
|
"prettier": "^3.5.0",
|
||||||
|
"ts-node-maintained": "^10.9.5",
|
||||||
|
"typescript": "~5.7"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@adonisjs/auth": "^9.3.1",
|
||||||
|
"@adonisjs/core": "^6.17.2",
|
||||||
|
"@adonisjs/cors": "^2.2.1",
|
||||||
|
"@adonisjs/limiter": "^2.4.0",
|
||||||
|
"@adonisjs/lucid": "^21.6.0",
|
||||||
|
"@vinejs/vine": "^3.0.0",
|
||||||
|
"luxon": "^3.6.1",
|
||||||
|
"pg": "^8.14.1",
|
||||||
|
"reflect-metadata": "^0.2.2"
|
||||||
|
},
|
||||||
|
"hotHook": {
|
||||||
|
"boundaries": [
|
||||||
|
"./app/controllers/**/*.ts",
|
||||||
|
"./app/middleware/*.ts"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"prettier": "@adonisjs/prettier-config"
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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.enum(['fatal', 'error', 'warn', 'info', 'debug', 'trace']),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
|
| 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(['database', 'memory'] as const),
|
||||||
|
})
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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('#middleware/force_json_response_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({
|
||||||
|
auth: () => import('#middleware/auth_middleware')
|
||||||
|
})
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import limiter from '@adonisjs/limiter/services/main'
|
||||||
|
export const throttle = limiter.define('global', () => {
|
||||||
|
return limiter.allowRequests(15).every('1 minute').blockFor('5 mins')
|
||||||
|
})
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Routes file
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The routes file is used for defining the HTTP routes.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import router from '@adonisjs/core/services/router'
|
||||||
|
import { middleware } from '#start/kernel'
|
||||||
|
import { throttle } from '#start/limiter'
|
||||||
|
|
||||||
|
const AuthController = () => import('#controllers/auth_controller')
|
||||||
|
|
||||||
|
router.post('/register', [AuthController, 'register']).as('auth.register').use(throttle)
|
||||||
|
router.post('/login', [AuthController, 'login']).as('auth.login').use(throttle)
|
||||||
|
router.delete('/logout', [AuthController, 'logout']).as('auth.logout').use(middleware.auth())
|
||||||
|
router.get('/me', [AuthController, 'me']).as('auth.me').use(middleware.auth())
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { assert } from '@japa/assert'
|
||||||
|
import { apiClient } from '@japa/api-client'
|
||||||
|
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(), apiClient(), 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())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "@adonisjs/tsconfig/tsconfig.app.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "./",
|
||||||
|
"outDir": "./build"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user