-
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: build / compile, swagger support & cluster mode
- Loading branch information
root
committed
Sep 6, 2024
1 parent
05c214d
commit 69d01b5
Showing
6 changed files
with
54 additions
and
16 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 |
---|---|---|
|
@@ -42,4 +42,7 @@ package-lock.json | |
**/*.bun | ||
|
||
# env files | ||
.env | ||
.env | ||
|
||
# ignore build | ||
dist/ |
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import os from "node:os"; | ||
|
||
export const APP_PORT = parseInt(process.env.APP_PORT || "3000") | ||
export const APP_WORKERS = parseInt(process.env.APP_WORKERS || os.availableParallelism().toString()); | ||
|
||
// Database configuration | ||
export const DB_HOST = process.env.DB_HOST | ||
export const DB_PORT = parseInt(process.env.DB_PORT || "5432") | ||
export const DB_USER = process.env.DB_USER | ||
export const DB_PASSWORD = process.env.DB_PASSWORD | ||
export const DB_NAME = process.env.DB_NAME | ||
export const DB_NAME = process.env.DB_NAME | ||
|
||
// Swagger configuration | ||
export const SWAGGER_PATH = "/documents" |
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,15 +1,19 @@ | ||
import { Elysia } from "elysia"; | ||
import exampleApp from "./example_app/routers"; | ||
import { APP_PORT } from "./config"; | ||
import staticPlugin from "@elysiajs/static"; | ||
import cluster from "node:cluster"; | ||
import process from "node:process"; | ||
import { APP_WORKERS } from "./config"; | ||
|
||
const app = new Elysia() | ||
// static plugin | ||
// more information: https://elysiajs.com/plugins/static | ||
.use(staticPlugin()) | ||
.use(exampleApp) | ||
.listen(APP_PORT); | ||
if (cluster.isPrimary) { | ||
console.log(`Primary ${process.pid} is running`); | ||
|
||
for (let i = 0; i < APP_WORKERS; i++) { | ||
cluster.fork(); | ||
} | ||
|
||
console.log( | ||
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}` | ||
); | ||
cluster.on("exit", (worker) => { | ||
console.log(`worker ${worker.process.pid} died`); | ||
process.exit(1); | ||
}); | ||
} else { | ||
await import("./server"); | ||
console.log(`Worker ${process.pid} started`); | ||
} |
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 { Elysia } from "elysia"; | ||
import staticPlugin from "@elysiajs/static"; | ||
import { swagger } from '@elysiajs/swagger' | ||
import { APP_PORT, SWAGGER_PATH } from "./config"; | ||
import exampleApp from "./example_app/routers"; | ||
|
||
const app = new Elysia() | ||
// static plugin | ||
// more information: https://elysiajs.com/plugins/static | ||
.use(staticPlugin()) | ||
// swagger plugin | ||
.use(swagger({ | ||
path: SWAGGER_PATH | ||
})) | ||
.use(exampleApp) | ||
.listen(APP_PORT); | ||
|
||
console.log( | ||
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}` | ||
); |