-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add AdonisJS alongside Express
- Loading branch information
1 parent
b681df5
commit 6dc1269
Showing
350 changed files
with
3,368 additions
and
928 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
APP_KEY= | ||
PORT= | ||
SERVER_PATH= | ||
API_ENV= | ||
|
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,31 @@ | ||
import { defineConfig } from "@adonisjs/core/app"; | ||
|
||
export default defineConfig({ | ||
commands: [() => import("@adonisjs/core/commands")], | ||
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"), | ||
], | ||
|
||
preloads: [ | ||
() => import("@backend/start/routes.js"), | ||
() => import("@backend/start/kernel.js"), | ||
], | ||
|
||
tests: { | ||
suites: [ | ||
{ | ||
files: ["src/tests/**/*.spec.ts"], | ||
name: "unit", | ||
timeout: 2000, | ||
}, | ||
], | ||
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,12 @@ | ||
import { HttpContext, ExceptionHandler } from "@adonisjs/core/http"; | ||
import app from "@adonisjs/core/services/app"; | ||
|
||
export default class HttpExceptionHandler extends ExceptionHandler { | ||
protected override debug = !app.inProduction; | ||
override async handle(error: unknown, ctx: HttpContext) { | ||
return super.handle(error, ctx); | ||
} | ||
override async report(error: unknown, ctx: HttpContext) { | ||
return super.report(error, ctx); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/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,12 @@ | ||
import { HttpContext } from "@adonisjs/core/http"; | ||
import { Logger } from "@adonisjs/core/logger"; | ||
import type { NextFn } from "@adonisjs/core/types/http"; | ||
|
||
export default class ContainerBindingsMiddleware { | ||
handle(ctx: HttpContext, next: NextFn) { | ||
ctx.containerResolver.bindValue(HttpContext, ctx); | ||
ctx.containerResolver.bindValue(Logger, ctx.logger); | ||
|
||
return next(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/app/middleware/force_json_response_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,11 @@ | ||
import type { HttpContext } from "@adonisjs/core/http"; | ||
import type { NextFn } from "@adonisjs/core/types/http"; | ||
|
||
export default class ForceJsonResponseMiddleware { | ||
async handle({ request }: HttpContext, next: NextFn) { | ||
const headers = request.headers(); | ||
headers.accept = "application/json"; | ||
|
||
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,25 @@ | ||
import "reflect-metadata"; | ||
import { Ignitor, prettyPrintError } from "@adonisjs/core"; | ||
|
||
const APP_ROOT = new URL("../", import.meta.url); | ||
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"); fixme migrate to adonis 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,25 @@ | ||
import "reflect-metadata"; | ||
import { Ignitor, prettyPrintError } from "@adonisjs/core"; | ||
|
||
const APP_ROOT = new URL("../", import.meta.url); | ||
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"); fixme migrate to AdonisJS env | ||
}); | ||
app.listen("SIGTERM", () => app.terminate()); | ||
app.listenIf(app.managedByPm2, "SIGINT", () => app.terminate()); | ||
}) | ||
.httpServer() | ||
.start() | ||
.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 |
---|---|---|
@@ -1,10 +1,36 @@ | ||
import "reflect-metadata"; | ||
import { Ignitor, prettyPrintError } from "@adonisjs/core"; | ||
import { apiClient } from "@japa/api-client"; | ||
import { assert } from "@japa/assert"; | ||
import { pluginAdonisJS } from "@japa/plugin-adonisjs"; | ||
import { configure, processCLIArgs, run } from "@japa/runner"; | ||
|
||
processCLIArgs(process.argv.splice(2)); | ||
configure({ | ||
files: ["src/tests/**/*.spec.ts"], | ||
plugins: [assert()], | ||
}); | ||
const APP_ROOT = new URL("../", import.meta.url); | ||
const IMPORTER = (filePath: string) => { | ||
if (filePath.startsWith("./") || filePath.startsWith("../")) { | ||
return import(new URL(filePath, APP_ROOT).href); | ||
} | ||
return import(filePath); | ||
}; | ||
|
||
run(); | ||
new Ignitor(APP_ROOT, { importer: IMPORTER }) | ||
.tap((app) => { | ||
app.booting(async () => { | ||
// await import('#start/env') fixme migrate to Adonis Env | ||
}); | ||
app.listen("SIGTERM", () => app.terminate()); | ||
app.listenIf(app.managedByPm2, "SIGINT", () => app.terminate()); | ||
}) | ||
.testRunner() | ||
.configure(async (app) => { | ||
processCLIArgs(process.argv.splice(2)); | ||
configure({ | ||
...app.rcFile.tests, | ||
plugins: [assert(), apiClient(), pluginAdonisJS(app)], | ||
}); | ||
}) | ||
.run(() => run()) | ||
.catch((error) => { | ||
process.exitCode = 1; | ||
prettyPrintError(error); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
import { Secret } from "@adonisjs/core/helpers"; | ||
import { defineConfig } from "@adonisjs/core/http"; | ||
import app from "@adonisjs/core/services/app"; | ||
import { BlEnv } from "@backend/express/config/env.js"; | ||
|
||
export const appKey = new Secret(BlEnv.APP_KEY); | ||
|
||
export const http = defineConfig({ | ||
generateRequestId: true, | ||
allowMethodSpoofing: false, | ||
useAsyncLocalStorage: false, | ||
cookie: { | ||
domain: "", | ||
path: "/", | ||
maxAge: "2h", | ||
httpOnly: true, | ||
secure: app.inProduction, | ||
sameSite: "lax", | ||
}, | ||
}); |
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,27 @@ | ||
import { defineConfig } from "@adonisjs/core/bodyparser"; | ||
|
||
const bodyParserConfig = defineConfig({ | ||
allowedMethods: ["POST", "PUT", "PATCH", "DELETE"], | ||
form: { | ||
convertEmptyStringsToNull: true, | ||
types: ["application/x-www-form-urlencoded"], | ||
}, | ||
json: { | ||
convertEmptyStringsToNull: true, | ||
types: [ | ||
"application/json", | ||
"application/json-patch+json", | ||
"application/vnd.api+json", | ||
"application/csp-report", | ||
], | ||
}, | ||
multipart: { | ||
autoProcess: true, | ||
convertEmptyStringsToNull: true, | ||
processManually: [], | ||
limit: "20mb", | ||
types: ["multipart/form-data"], | ||
}, | ||
}); | ||
|
||
export default bodyParserConfig; |
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,13 @@ | ||
import { defineConfig } from "@adonisjs/cors"; | ||
|
||
const corsConfig = defineConfig({ | ||
enabled: true, | ||
origin: true, | ||
methods: ["GET", "HEAD", "POST", "PUT", "DELETE"], | ||
headers: true, | ||
exposeHeaders: [], | ||
credentials: true, | ||
maxAge: 90, | ||
}); | ||
|
||
export default corsConfig; |
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,21 @@ | ||
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; | ||
|
||
declare module "@adonisjs/core/types" { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
export interface HashersList extends InferHashers<typeof hashConfig> {} | ||
} |
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,27 @@ | ||
import { defineConfig, targets } from "@adonisjs/core/logger"; | ||
import app from "@adonisjs/core/services/app"; | ||
|
||
const loggerConfig = defineConfig({ | ||
default: "app", | ||
|
||
loggers: { | ||
app: { | ||
enabled: true, | ||
name: "backend", | ||
level: "debug", | ||
transport: { | ||
targets: targets() | ||
.pushIf(!app.inProduction, targets.pretty()) | ||
.pushIf(app.inProduction, targets.file({ destination: 1 })) | ||
.toArray(), | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
export default loggerConfig; | ||
|
||
declare module "@adonisjs/core/types" { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
export interface LoggersList extends InferLoggers<typeof loggerConfig> {} | ||
} |
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
Oops, something went wrong.