Skip to content

Commit 5d1f52f

Browse files
committed
add adonisjs
1 parent a2b391a commit 5d1f52f

38 files changed

+9592
-3
lines changed

adonisjs/.dockerignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Dependencies and AdonisJS build
2+
node_modules
3+
build
4+
tmp
5+
6+
# Secrets
7+
.env
8+
.env.local
9+
.env.production.local
10+
.env.development.local
11+
12+
# Frontend assets compiled code
13+
public/assets
14+
15+
# Build tools specific
16+
npm-debug.log
17+
yarn-error.log
18+
19+
# Editors specific
20+
.fleet
21+
.idea
22+
.vscode
23+
24+
# Platform specific
25+
.DS_Store
26+
valyent.json

adonisjs/.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# http://editorconfig.org
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.json]
12+
insert_final_newline = unset
13+
14+
[**.min.js]
15+
indent_style = unset
16+
insert_final_newline = unset
17+
18+
[MakeFile]
19+
indent_style = space
20+
21+
[*.md]
22+
trim_trailing_whitespace = false

adonisjs/.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
TZ=UTC
2+
PORT=3333
3+
HOST=localhost
4+
LOG_LEVEL=info
5+
APP_KEY=
6+
NODE_ENV=development

adonisjs/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Dependencies and AdonisJS build
2+
node_modules
3+
build
4+
tmp
5+
6+
# Secrets
7+
.env
8+
.env.local
9+
.env.production.local
10+
.env.development.local
11+
12+
# Frontend assets compiled code
13+
public/assets
14+
15+
# Build tools specific
16+
npm-debug.log
17+
yarn-error.log
18+
19+
# Editors specific
20+
.fleet
21+
.idea
22+
.vscode
23+
24+
# Platform specific
25+
.DS_Store
26+
valyent.json

adonisjs/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM node:20.12.2-alpine3.18 AS base
2+
3+
# All deps stage
4+
FROM base AS deps
5+
WORKDIR /app
6+
ADD package.json package-lock.json ./
7+
RUN npm ci
8+
9+
# Production only deps stage
10+
FROM base AS production-deps
11+
WORKDIR /app
12+
ADD package.json package-lock.json ./
13+
RUN npm ci --omit=dev
14+
15+
# Build stage
16+
FROM base AS build
17+
WORKDIR /app
18+
COPY --from=deps /app/node_modules /app/node_modules
19+
ADD . .
20+
RUN node ace build
21+
22+
# Production stage
23+
FROM base
24+
ENV NODE_ENV=production
25+
WORKDIR /app
26+
COPY --from=production-deps /app/node_modules /app/node_modules
27+
COPY --from=build /app/build /app
28+
EXPOSE 8080
29+
CMD ["node", "./bin/server.js"]

adonisjs/ace.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
|--------------------------------------------------------------------------
3+
| JavaScript entrypoint for running ace commands
4+
|--------------------------------------------------------------------------
5+
|
6+
| DO NOT MODIFY THIS FILE AS IT WILL BE OVERRIDDEN DURING THE BUILD
7+
| PROCESS.
8+
|
9+
| See docs.adonisjs.com/guides/typescript-build-process#creating-production-build
10+
|
11+
| Since, we cannot run TypeScript source code using "node" binary, we need
12+
| a JavaScript entrypoint to run ace commands.
13+
|
14+
| This file registers the "ts-node/esm" hook with the Node.js module system
15+
| and then imports the "bin/console.ts" file.
16+
|
17+
*/
18+
19+
/**
20+
* Register hook to process TypeScript files using ts-node
21+
*/
22+
import 'ts-node-maintained/register/esm'
23+
24+
/**
25+
* Import ace console entrypoint
26+
*/
27+
await import('./bin/console.js')

adonisjs/adonisrc.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { defineConfig } from '@adonisjs/core/app'
2+
3+
export default defineConfig({
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Commands
7+
|--------------------------------------------------------------------------
8+
|
9+
| List of ace commands to register from packages. The application commands
10+
| will be scanned automatically from the "./commands" directory.
11+
|
12+
*/
13+
commands: [() => import('@adonisjs/core/commands')],
14+
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Service providers
18+
|--------------------------------------------------------------------------
19+
|
20+
| List of service providers to import and register when booting the
21+
| application
22+
|
23+
*/
24+
providers: [
25+
() => import('@adonisjs/core/providers/app_provider'),
26+
() => import('@adonisjs/core/providers/hash_provider'),
27+
{
28+
file: () => import('@adonisjs/core/providers/repl_provider'),
29+
environment: ['repl', 'test'],
30+
},
31+
],
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Preloads
36+
|--------------------------------------------------------------------------
37+
|
38+
| List of modules to import before starting the application.
39+
|
40+
*/
41+
preloads: [() => import('#start/routes'), () => import('#start/kernel')],
42+
43+
/*
44+
|--------------------------------------------------------------------------
45+
| Tests
46+
|--------------------------------------------------------------------------
47+
|
48+
| List of test suites to organize tests by their type. Feel free to remove
49+
| and add additional suites.
50+
|
51+
*/
52+
tests: {
53+
suites: [
54+
{
55+
files: ['tests/unit/**/*.spec(.ts|.js)'],
56+
name: 'unit',
57+
timeout: 2000,
58+
},
59+
{
60+
files: ['tests/functional/**/*.spec(.ts|.js)'],
61+
name: 'functional',
62+
timeout: 30000,
63+
},
64+
],
65+
forceExit: false,
66+
},
67+
})

adonisjs/app/exceptions/handler.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import app from '@adonisjs/core/services/app'
2+
import { HttpContext, ExceptionHandler } from '@adonisjs/core/http'
3+
4+
export default class HttpExceptionHandler extends ExceptionHandler {
5+
/**
6+
* In debug mode, the exception handler will display verbose errors
7+
* with pretty printed stack traces.
8+
*/
9+
protected debug = !app.inProduction
10+
11+
/**
12+
* Status pages are used to display a custom HTML pages for certain error
13+
* codes. You might want to enable them in production only, but feel
14+
* free to enable them in development as well.
15+
*/
16+
protected renderStatusPages = app.inProduction
17+
18+
/**
19+
* The method is used for handling errors and returning
20+
* response to the client
21+
*/
22+
async handle(error: unknown, ctx: HttpContext) {
23+
return super.handle(error, ctx)
24+
}
25+
26+
/**
27+
* The method is used to report error to the logging service or
28+
* the a third party error monitoring service.
29+
*
30+
* @note You should not attempt to send a response from this method.
31+
*/
32+
async report(error: unknown, ctx: HttpContext) {
33+
return super.report(error, ctx)
34+
}
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Logger } from '@adonisjs/core/logger'
2+
import { HttpContext } from '@adonisjs/core/http'
3+
import type { NextFn } from '@adonisjs/core/types/http'
4+
5+
/**
6+
* The container bindings middleware binds classes to their request
7+
* specific value using the container resolver.
8+
*
9+
* - We bind "HttpContext" class to the "ctx" object
10+
* - And bind "Logger" class to the "ctx.logger" object
11+
*/
12+
export default class ContainerBindingsMiddleware {
13+
handle(ctx: HttpContext, next: NextFn) {
14+
ctx.containerResolver.bindValue(HttpContext, ctx)
15+
ctx.containerResolver.bindValue(Logger, ctx.logger)
16+
17+
return next()
18+
}
19+
}

adonisjs/bin/console.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
|--------------------------------------------------------------------------
3+
| Ace entry point
4+
|--------------------------------------------------------------------------
5+
|
6+
| The "console.ts" file is the entrypoint for booting the AdonisJS
7+
| command-line framework and executing commands.
8+
|
9+
| Commands do not boot the application, unless the currently running command
10+
| has "options.startApp" flag set to true.
11+
|
12+
*/
13+
14+
import 'reflect-metadata'
15+
import { Ignitor, prettyPrintError } from '@adonisjs/core'
16+
17+
/**
18+
* URL to the application root. AdonisJS need it to resolve
19+
* paths to file and directories for scaffolding commands
20+
*/
21+
const APP_ROOT = new URL('../', import.meta.url)
22+
23+
/**
24+
* The importer is used to import files in context of the
25+
* application.
26+
*/
27+
const IMPORTER = (filePath: string) => {
28+
if (filePath.startsWith('./') || filePath.startsWith('../')) {
29+
return import(new URL(filePath, APP_ROOT).href)
30+
}
31+
return import(filePath)
32+
}
33+
34+
new Ignitor(APP_ROOT, { importer: IMPORTER })
35+
.tap((app) => {
36+
app.booting(async () => {
37+
await import('#start/env')
38+
})
39+
app.listen('SIGTERM', () => app.terminate())
40+
app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate())
41+
})
42+
.ace()
43+
.handle(process.argv.splice(2))
44+
.catch((error) => {
45+
process.exitCode = 1
46+
prettyPrintError(error)
47+
})

0 commit comments

Comments
 (0)