first commit
This commit is contained in:
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
|
||||||
12
.env.example
Normal file
12
.env.example
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
TZ=UTC
|
||||||
|
PORT=3333
|
||||||
|
HOST=localhost
|
||||||
|
LOG_LEVEL=info
|
||||||
|
APP_KEY=
|
||||||
|
NODE_ENV=development
|
||||||
|
SESSION_DRIVER=cookie
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_USER=root
|
||||||
|
DB_PASSWORD=root
|
||||||
|
DB_DATABASE=app
|
||||||
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')
|
||||||
107
adonisrc.ts
Normal file
107
adonisrc.ts
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
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')],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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/core/providers/edge_provider'),
|
||||||
|
() => import('@adonisjs/session/session_provider'),
|
||||||
|
() => import('@adonisjs/vite/vite_provider'),
|
||||||
|
() => import('@adonisjs/shield/shield_provider'),
|
||||||
|
() => import('@adonisjs/static/static_provider'),
|
||||||
|
() => import('@adonisjs/lucid/database_provider'),
|
||||||
|
() => import('@adonisjs/auth/auth_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,
|
||||||
|
},
|
||||||
|
|
||||||
|
metaFiles: [
|
||||||
|
{
|
||||||
|
pattern: 'resources/views/**/*.edge',
|
||||||
|
reloadServer: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: 'public/**',
|
||||||
|
reloadServer: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
assetsBundler: false,
|
||||||
|
hooks: {
|
||||||
|
onBuildStarting: [() => import('@adonisjs/vite/build_hook')],
|
||||||
|
},
|
||||||
|
assetsBundler: false
|
||||||
|
})
|
||||||
43
app/controllers/sections_controller.ts
Normal file
43
app/controllers/sections_controller.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
|
import Section from '#models/section'
|
||||||
|
import { inject } from '@adonisjs/core'
|
||||||
|
|
||||||
|
export default class SectionsController {
|
||||||
|
/**
|
||||||
|
* Display a list of resource
|
||||||
|
*/
|
||||||
|
@inject()
|
||||||
|
async index({}: HttpContext) {
|
||||||
|
return Section.query().orderBy('asc')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display form to create a new record
|
||||||
|
*/
|
||||||
|
async create({}: HttpContext) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle form submission for the create action
|
||||||
|
*/
|
||||||
|
async store({ request }: HttpContext) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show individual record
|
||||||
|
*/
|
||||||
|
async show({ params }: HttpContext) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit individual record
|
||||||
|
*/
|
||||||
|
async edit({ params }: HttpContext) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle form submission for the edit action
|
||||||
|
*/
|
||||||
|
async update({ params, request }: HttpContext) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete record
|
||||||
|
*/
|
||||||
|
async destroy({ params }: HttpContext) {}
|
||||||
|
}
|
||||||
49
app/exceptions/handler.ts
Normal file
49
app/exceptions/handler.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import app from '@adonisjs/core/services/app'
|
||||||
|
import { HttpContext, ExceptionHandler } from '@adonisjs/core/http'
|
||||||
|
import type { StatusPageRange, StatusPageRenderer } from '@adonisjs/core/types/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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status pages is a collection of error code range and a callback
|
||||||
|
* to return the HTML contents to send as a response.
|
||||||
|
*/
|
||||||
|
protected statusPages: Record<StatusPageRange, StatusPageRenderer> = {
|
||||||
|
'404': (error, { view }) => {
|
||||||
|
return view.render('pages/errors/not_found', { error })
|
||||||
|
},
|
||||||
|
'500..599': (error, { view }) => {
|
||||||
|
return view.render('pages/errors/server_error', { error })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 { 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/models/section.ts
Normal file
16
app/models/section.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { DateTime } from 'luxon'
|
||||||
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
||||||
|
|
||||||
|
export default class Section extends BaseModel {
|
||||||
|
@column({ isPrimary: true })
|
||||||
|
declare id: number
|
||||||
|
|
||||||
|
@column({})
|
||||||
|
declare name: string
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true })
|
||||||
|
declare createdAt: DateTime
|
||||||
|
|
||||||
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||||
|
declare updatedAt: DateTime
|
||||||
|
}
|
||||||
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/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: 'mysql',
|
||||||
|
connections: {
|
||||||
|
mysql: {
|
||||||
|
client: 'mysql2',
|
||||||
|
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
|
||||||
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> {}
|
||||||
|
}
|
||||||
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> {}
|
||||||
|
}
|
||||||
48
config/session.ts
Normal file
48
config/session.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import env from '#start/env'
|
||||||
|
import app from '@adonisjs/core/services/app'
|
||||||
|
import { defineConfig, stores } from '@adonisjs/session'
|
||||||
|
|
||||||
|
const sessionConfig = defineConfig({
|
||||||
|
enabled: true,
|
||||||
|
cookieName: 'adonis-session',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When set to true, the session id cookie will be deleted
|
||||||
|
* once the user closes the browser.
|
||||||
|
*/
|
||||||
|
clearWithBrowser: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define how long to keep the session data alive without
|
||||||
|
* any activity.
|
||||||
|
*/
|
||||||
|
age: '2h',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for session cookie and the
|
||||||
|
* cookie store
|
||||||
|
*/
|
||||||
|
cookie: {
|
||||||
|
path: '/',
|
||||||
|
httpOnly: true,
|
||||||
|
secure: app.inProduction,
|
||||||
|
sameSite: 'lax',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The store to use. Make sure to validate the environment
|
||||||
|
* variable in order to infer the store name without any
|
||||||
|
* errors.
|
||||||
|
*/
|
||||||
|
store: env.get('SESSION_DRIVER'),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of configured stores. Refer documentation to see
|
||||||
|
* list of available stores and their config.
|
||||||
|
*/
|
||||||
|
stores: {
|
||||||
|
cookie: stores.cookie(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default sessionConfig
|
||||||
51
config/shield.ts
Normal file
51
config/shield.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { defineConfig } from '@adonisjs/shield'
|
||||||
|
|
||||||
|
const shieldConfig = defineConfig({
|
||||||
|
/**
|
||||||
|
* Configure CSP policies for your app. Refer documentation
|
||||||
|
* to learn more
|
||||||
|
*/
|
||||||
|
csp: {
|
||||||
|
enabled: false,
|
||||||
|
directives: {},
|
||||||
|
reportOnly: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure CSRF protection options. Refer documentation
|
||||||
|
* to learn more
|
||||||
|
*/
|
||||||
|
csrf: {
|
||||||
|
enabled: true,
|
||||||
|
exceptRoutes: [],
|
||||||
|
enableXsrfCookie: false,
|
||||||
|
methods: ['POST', 'PUT', 'PATCH', 'DELETE'],
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control how your website should be embedded inside
|
||||||
|
* iFrames
|
||||||
|
*/
|
||||||
|
xFrame: {
|
||||||
|
enabled: true,
|
||||||
|
action: 'DENY',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force browser to always use HTTPS
|
||||||
|
*/
|
||||||
|
hsts: {
|
||||||
|
enabled: true,
|
||||||
|
maxAge: '180 days',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable browsers from sniffing the content type of a
|
||||||
|
* response and always rely on the "content-type" header.
|
||||||
|
*/
|
||||||
|
contentTypeSniffing: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default shieldConfig
|
||||||
17
config/static.ts
Normal file
17
config/static.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { defineConfig } from '@adonisjs/static'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration options to tweak the static files middleware.
|
||||||
|
* The complete set of options are documented on the
|
||||||
|
* official documentation website.
|
||||||
|
*
|
||||||
|
* https://docs.adonisjs.com/guides/basics/static-file-server
|
||||||
|
*/
|
||||||
|
const staticServerConfig = defineConfig({
|
||||||
|
enabled: true,
|
||||||
|
etag: true,
|
||||||
|
lastModified: true,
|
||||||
|
dotFiles: 'ignore',
|
||||||
|
})
|
||||||
|
|
||||||
|
export default staticServerConfig
|
||||||
28
config/vite.ts
Normal file
28
config/vite.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { defineConfig } from '@adonisjs/vite'
|
||||||
|
|
||||||
|
const viteBackendConfig = defineConfig({
|
||||||
|
/**
|
||||||
|
* The output of vite will be written inside this
|
||||||
|
* directory. The path should be relative from
|
||||||
|
* the application root.
|
||||||
|
*/
|
||||||
|
buildDirectory: 'public/assets',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path to the manifest file generated by the
|
||||||
|
* "vite build" command.
|
||||||
|
*/
|
||||||
|
manifestFile: 'public/assets/.vite/manifest.json',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Feel free to change the value of the "assetsUrl" to
|
||||||
|
* point to a CDN in production.
|
||||||
|
*/
|
||||||
|
assetsUrl: '/assets',
|
||||||
|
|
||||||
|
scriptAttributes: {
|
||||||
|
defer: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default viteBackendConfig
|
||||||
21
database/migrations/1769601928154_create_users_table.ts
Normal file
21
database/migrations/1769601928154_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)
|
||||||
|
}
|
||||||
|
}
|
||||||
18
database/migrations/1769602894566_create_sections_table.ts
Normal file
18
database/migrations/1769602894566_create_sections_table.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { BaseSchema } from '@adonisjs/lucid/schema'
|
||||||
|
|
||||||
|
export default class extends BaseSchema {
|
||||||
|
protected tableName = 'sections'
|
||||||
|
|
||||||
|
async up() {
|
||||||
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
|
table.increments('id')
|
||||||
|
table.text('name').notNullable()
|
||||||
|
table.timestamp('created_at')
|
||||||
|
table.timestamp('updated_at')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async down() {
|
||||||
|
this.schema.dropTable(this.tableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
21
database/seeders/section_seeder.ts
Normal file
21
database/seeders/section_seeder.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { BaseSeeder } from '@adonisjs/lucid/seeders'
|
||||||
|
import Section from '#models/section'
|
||||||
|
|
||||||
|
export default class extends BaseSeeder {
|
||||||
|
async run() {
|
||||||
|
await Section.createMany([
|
||||||
|
{
|
||||||
|
name: 'Informatique',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Mecanique',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Electronique',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Polymécanique',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
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()
|
||||||
8984
package-lock.json
generated
Normal file
8984
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
75
package.json
Normal file
75
package.json
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
{
|
||||||
|
"name": "sections",
|
||||||
|
"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",
|
||||||
|
"#tests/*": "./tests/*.js",
|
||||||
|
"#start/*": "./start/*.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.7.1",
|
||||||
|
"@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",
|
||||||
|
"vite": "^6.4.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@adonisjs/auth": "^9.4.0",
|
||||||
|
"@adonisjs/core": "^6.18.0",
|
||||||
|
"@adonisjs/lucid": "^21.8.2",
|
||||||
|
"@adonisjs/session": "^7.5.1",
|
||||||
|
"@adonisjs/shield": "^8.2.0",
|
||||||
|
"@adonisjs/static": "^1.1.1",
|
||||||
|
"@adonisjs/vite": "^4.0.0",
|
||||||
|
"@vinejs/vine": "^3.0.1",
|
||||||
|
"better-sqlite3": "^12.6.2",
|
||||||
|
"edge.js": "^6.2.1",
|
||||||
|
"luxon": "^3.7.2",
|
||||||
|
"mysql2": "^3.16.2",
|
||||||
|
"reflect-metadata": "^0.2.2"
|
||||||
|
},
|
||||||
|
"hotHook": {
|
||||||
|
"boundaries": [
|
||||||
|
"./app/controllers/**/*.ts",
|
||||||
|
"./app/middleware/*.ts"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"prettier": "@adonisjs/prettier-config"
|
||||||
|
}
|
||||||
10
resources/css/app.css
Normal file
10
resources/css/app.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
1
resources/js/app.js
Normal file
1
resources/js/app.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
console.log('Hello World')
|
||||||
8
resources/views/pages/errors/not_found.edge
Normal file
8
resources/views/pages/errors/not_found.edge
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<h1>
|
||||||
|
404 - Page not found
|
||||||
|
</h1>
|
||||||
|
<p>
|
||||||
|
This template is rendered by the
|
||||||
|
<a href="http://docs.adonisjs.com/guides/exception-handling#status-pages">status pages feature</a>
|
||||||
|
of the global exception handler.
|
||||||
|
</p>
|
||||||
8
resources/views/pages/errors/server_error.edge
Normal file
8
resources/views/pages/errors/server_error.edge
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<h1>
|
||||||
|
{{ error.code }} - Server error
|
||||||
|
</h1>
|
||||||
|
<p>
|
||||||
|
This template is rendered by the
|
||||||
|
<a href="http://docs.adonisjs.com/guides/exception-handling#status-pages">status pages feature</a>
|
||||||
|
of the global exception handler.
|
||||||
|
</p>
|
||||||
73
resources/views/pages/home.edge
Normal file
73
resources/views/pages/home.edge
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>
|
||||||
|
AdonisJS - A fully featured web framework for Node.js
|
||||||
|
</title>
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.bunny.net" />
|
||||||
|
<link
|
||||||
|
href="https://fonts.bunny.net/css?family=instrument-sans:400,400i,500,500i,600,600i,700,700i"
|
||||||
|
rel="stylesheet"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--sand-1: #fdfdfc;
|
||||||
|
--sand-2: #f9f9f8;
|
||||||
|
--sand-3: #f1f0ef;
|
||||||
|
--sand-4: #e9e8e6;
|
||||||
|
--sand-5: #e2e1de;
|
||||||
|
--sand-6: #dad9d6;
|
||||||
|
--sand-7: #cfceca;
|
||||||
|
--sand-8: #bcbbb5;
|
||||||
|
--sand-9: #8d8d86;
|
||||||
|
--sand-10: #82827c;
|
||||||
|
--sand-11: #63635e;
|
||||||
|
--sand-12: #21201c;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
tailwind.config = {
|
||||||
|
theme: {
|
||||||
|
extend: {
|
||||||
|
fontFamily: {
|
||||||
|
sans: [ "Instrument Sans", "sans-serif" ]
|
||||||
|
},
|
||||||
|
colors: {
|
||||||
|
primary: {
|
||||||
|
DEFAULT: "#5A45FF",
|
||||||
|
lighter: "#a599ff"
|
||||||
|
},
|
||||||
|
sand: {
|
||||||
|
1: "var(--sand-1)",
|
||||||
|
2: "var(--sand-2)",
|
||||||
|
3: "var(--sand-3)",
|
||||||
|
4: "var(--sand-4)",
|
||||||
|
5: "var(--sand-5)",
|
||||||
|
6: "var(--sand-6)",
|
||||||
|
7: "var(--sand-7)",
|
||||||
|
8: "var(--sand-8)",
|
||||||
|
9: "var(--sand-9)",
|
||||||
|
10: "var(--sand-10)",
|
||||||
|
11: "var(--sand-11)",
|
||||||
|
12: "var(--sand-12)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
||||||
|
@stack('dumper')
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1><a href="/sections">Voir les sections</a></h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
18
resources/views/pages/sections.edge
Normal file
18
resources/views/pages/sections.edge
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>
|
||||||
|
Sections
|
||||||
|
</h1>
|
||||||
|
<ul>
|
||||||
|
@each(section in sections)
|
||||||
|
<li> {{ section.name }} <button>🗑</button></li>
|
||||||
|
@end
|
||||||
|
|
||||||
|
<li>Informatique <button>🗑</button></li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
38
start/env.ts
Normal file
38
start/env.ts
Normal file
@@ -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.string(),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
|
| Variables for configuring session package
|
||||||
|
|----------------------------------------------------------
|
||||||
|
*/
|
||||||
|
SESSION_DRIVER: Env.schema.enum(['cookie', 'memory'] as const),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
|
| 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()
|
||||||
|
})
|
||||||
49
start/kernel.ts
Normal file
49
start/kernel.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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 an 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/static/static_middleware'),
|
||||||
|
() => import('@adonisjs/vite/vite_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/session/session_middleware'),
|
||||||
|
() => import('@adonisjs/shield/shield_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/routes.ts
Normal file
16
start/routes.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Routes file
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The routes file is used for defining the HTTP routes.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import router from '@adonisjs/core/services/router'
|
||||||
|
import SectionsController from '#controllers/sections_controller'
|
||||||
|
|
||||||
|
router.on('/').render('pages/home')
|
||||||
|
router.on('sections').render('pages/sections')
|
||||||
|
router.get('api/sections', [SectionsController, 'index'])
|
||||||
|
router.delete('api/section/:id', [SectionsController, 'destroy'])
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
vite.config.ts
Normal file
19
vite.config.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import adonisjs from '@adonisjs/vite/client'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [
|
||||||
|
adonisjs({
|
||||||
|
/**
|
||||||
|
* Entrypoints of your application. Each entrypoint will
|
||||||
|
* result in a separate bundle.
|
||||||
|
*/
|
||||||
|
entrypoints: ['resources/css/app.css', 'resources/js/app.js'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paths to watch and reload the browser on file change
|
||||||
|
*/
|
||||||
|
reload: ['resources/views/**/*.edge'],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user