-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29127db
commit 2ea80a4
Showing
20 changed files
with
6,041 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| 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 { register } from 'node:module' | ||
register('ts-node/esm', import.meta.url) | ||
|
||
/** | ||
* Import ace console entrypoint | ||
*/ | ||
await import('./bin/console.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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')], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| 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'], | ||
}, | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| 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, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import app from '@adonisjs/core/services/app' | ||
import { HttpContext, ExceptionHandler } from '@adonisjs/core/http' | ||
|
||
export default class HttpExceptionHandler extends ExceptionHandler { | ||
/** | ||
* In debug mode, the exception handler will display verbose errors | ||
* with pretty printed stack traces. | ||
*/ | ||
protected debug = !app.inProduction | ||
|
||
/** | ||
* Status pages are used to display a custom HTML pages for certain error | ||
* codes. You might want to enable them in production only, but feel | ||
* free to enable them in development as well. | ||
*/ | ||
protected renderStatusPages = app.inProduction | ||
|
||
/** | ||
* The method is used for handling errors and returning | ||
* response to the client | ||
*/ | ||
async handle(error: unknown, ctx: HttpContext) { | ||
return super.handle(error, ctx) | ||
} | ||
|
||
/** | ||
* The method is used to report error to the logging service or | ||
* the a third party error monitoring service. | ||
* | ||
* @note You should not attempt to send a response from this method. | ||
*/ | ||
async report(error: unknown, ctx: HttpContext) { | ||
return super.report(error, ctx) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
examples/adonisjs/app/middleware/container_bindings_middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |
Oops, something went wrong.