deploy-bbc 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +345 -0
- package/dist/index.js +16870 -0
- package/dist/templates/base/package.json +20 -0
- package/dist/templates/base/src/routes/index.ts +12 -0
- package/dist/templates/base/src/types/index.ts +2 -0
- package/dist/templates/base-bun-native/package.json +19 -0
- package/dist/templates/base-bun-native/src/index.ts +50 -0
- package/dist/templates/base-bun-native/src/routes/index.ts +21 -0
- package/dist/templates/base-bun-native/src/types/index.ts +2 -0
- package/dist/templates/base-express/package.json +21 -0
- package/dist/templates/base-express/src/routes/index.ts +12 -0
- package/dist/templates/base-express/src/types/index.ts +2 -0
- package/dist/templates/templates/base/.env.example +3 -0
- package/dist/templates/templates/base/README.md +31 -0
- package/dist/templates/templates/base/src/config/index.ts +8 -0
- package/dist/templates/templates/base/src/index.ts +26 -0
- package/dist/templates/templates/base/src/middleware/error.ts +13 -0
- package/dist/templates/templates/base/src/middleware/logger.ts +8 -0
- package/dist/templates/templates/base/src/utils/env.ts +5 -0
- package/dist/templates/templates/base/tsconfig.json +20 -0
- package/dist/templates/templates/base-bun-native/.env.example +3 -0
- package/dist/templates/templates/base-bun-native/README.md +31 -0
- package/dist/templates/templates/base-bun-native/src/config/index.ts +8 -0
- package/dist/templates/templates/base-bun-native/src/middleware/error.ts +20 -0
- package/dist/templates/templates/base-bun-native/src/middleware/logger.ts +6 -0
- package/dist/templates/templates/base-bun-native/src/utils/env.ts +5 -0
- package/dist/templates/templates/base-bun-native/tsconfig.json +20 -0
- package/dist/templates/templates/base-express/.env.example +3 -0
- package/dist/templates/templates/base-express/README.md +31 -0
- package/dist/templates/templates/base-express/src/config/index.ts +8 -0
- package/dist/templates/templates/base-express/src/index.ts +27 -0
- package/dist/templates/templates/base-express/src/middleware/error.ts +15 -0
- package/dist/templates/templates/base-express/src/middleware/logger.ts +12 -0
- package/dist/templates/templates/base-express/src/utils/env.ts +5 -0
- package/dist/templates/templates/base-express/tsconfig.json +20 -0
- package/dist/templates/templates/extras/ai/anthropic/src/services/ai/anthropic.ts +0 -0
- package/dist/templates/templates/extras/ai/gemini/src/services/ai/gemini.ts +0 -0
- package/dist/templates/templates/extras/ai/openai/src/routes/ai/chat.ts +0 -0
- package/dist/templates/templates/extras/ai/openai/src/services/ai/openai.ts +0 -0
- package/dist/templates/templates/extras/ai/vercel-ai/src/routes/ai/generate.ts +0 -0
- package/dist/templates/templates/extras/ai/vercel-ai/src/routes/ai/stream.ts +0 -0
- package/dist/templates/templates/extras/ai/vercel-ai/src/services/ai/index.ts +0 -0
- package/dist/templates/templates/extras/auth/jwt/src/middleware/auth.ts +0 -0
- package/dist/templates/templates/extras/auth/jwt/src/routes/auth.ts +0 -0
- package/dist/templates/templates/extras/auth/jwt/src/utils/jwt.ts +0 -0
- package/dist/templates/templates/extras/auth/oauth/src/config/oauth.ts +0 -0
- package/dist/templates/templates/extras/auth/oauth/src/routes/auth.ts +0 -0
- package/dist/templates/templates/extras/auth/session/src/config/session.ts +0 -0
- package/dist/templates/templates/extras/auth/session/src/middleware/session.ts +0 -0
- package/dist/templates/templates/extras/cloud/aws/src/services/aws/s3.ts +0 -0
- package/dist/templates/templates/extras/cloud/aws/src/services/aws/ses.ts +0 -0
- package/dist/templates/templates/extras/cloud/azure/src/services/azure/blob.ts +0 -0
- package/dist/templates/templates/extras/cloud/cloudflare-r2/src/services/cloudflare/r2.ts +0 -0
- package/dist/templates/templates/extras/cloud/gcp/src/services/gcp/storage.ts +0 -0
- package/dist/templates/templates/extras/database/mongodb/src/db/index.ts +0 -0
- package/dist/templates/templates/extras/database/mongodb/src/db/models/user.model.ts +0 -0
- package/dist/templates/templates/extras/database/mysql/drizzle.config.ts +0 -0
- package/dist/templates/templates/extras/database/postgres/src/db/index.ts +0 -0
- package/dist/templates/templates/extras/database/redis/src/db/redis.ts +0 -0
- package/dist/templates/templates/extras/docs/scalar/src/openapi/index.ts +0 -0
- package/dist/templates/templates/extras/docs/scalar/src/routes/docs.ts +0 -0
- package/dist/templates/templates/extras/docs/swagger/src/openapi/index.ts +0 -0
- package/dist/templates/templates/extras/docs/swagger/src/routes/docs.ts +0 -0
- package/dist/templates/templates/extras/email/nodemailer/src/services/email/nodemailer.ts +0 -0
- package/dist/templates/templates/extras/email/resend/src/services/email/resend.ts +0 -0
- package/dist/templates/templates/extras/email/resend/src/templates/email/welcome.ts +0 -0
- package/dist/templates/templates/extras/email/sendgrid/src/services/email/sendgrid.ts +0 -0
- package/dist/templates/templates/extras/observability/logtail/src/config/logger.ts +0 -0
- package/dist/templates/templates/extras/observability/sentry/src/config/sentry.ts +0 -0
- package/dist/templates/templates/extras/observability/sentry/src/middleware/sentry.ts +0 -0
- package/dist/templates/templates/extras/queue/bullmq/src/queue/index.ts +0 -0
- package/dist/templates/templates/extras/queue/bullmq/src/queue/jobs/email.job.ts +0 -0
- package/dist/templates/templates/extras/queue/bullmq/src/queue/processors/email.processor.ts +0 -0
- package/dist/templates/templates/extras/queue/bullmq/src/routes/queue.ts +0 -0
- package/dist/templates/templates/extras/queue/inngest/src/inngest/client.ts +0 -0
- package/dist/templates/templates/extras/queue/inngest/src/inngest/functions/email.ts +0 -0
- package/dist/templates/templates/extras/queue/inngest/src/routes/inngest.ts +0 -0
- package/dist/templates/templates/extras/realtime/socketio/src/socket/handlers.ts +0 -0
- package/dist/templates/templates/extras/realtime/socketio/src/socket/index.ts +0 -0
- package/dist/templates/templates/extras/realtime/sse/src/routes/sse.ts +0 -0
- package/dist/templates/templates/extras/testing/vitest/src/__tests__/example.test.ts +0 -0
- package/dist/templates/templates/extras/testing/vitest/src/__tests__/setup.ts +0 -0
- package/dist/templates/templates/extras/testing/vitest/vitest.config.ts +0 -0
- package/dist/templates/templates/extras/validation/yup/src/middleware/index.ts +1 -0
- package/dist/templates/templates/extras/validation/yup/src/middleware/validate.ts +83 -0
- package/dist/templates/templates/extras/validation/yup/src/routes/users.ts +132 -0
- package/dist/templates/templates/extras/validation/zod/src/middleware/index.ts +1 -0
- package/dist/templates/templates/extras/validation/zod/src/middleware/validate.ts +80 -0
- package/dist/templates/templates/extras/validation/zod/src/routes/users.ts +128 -0
- package/package.json +43 -9
- package/CLAUDE.md +0 -403
- package/cli/README.md +0 -345
- package/cli/package.json +0 -54
- package/cli/src/cli/index.ts +0 -454
- package/cli/src/helpers/create-project.ts +0 -66
- package/cli/src/helpers/generate-docker-compose.ts +0 -133
- package/cli/src/helpers/generate-dockerfile.ts +0 -45
- package/cli/src/helpers/init-git.ts +0 -33
- package/cli/src/helpers/install-dependencies.ts +0 -28
- package/cli/src/helpers/log-next-steps.ts +0 -87
- package/cli/src/helpers/scaffold-project.ts +0 -88
- package/cli/src/index.ts +0 -18
- package/cli/src/installers/ai.ts +0 -123
- package/cli/src/installers/auth.ts +0 -132
- package/cli/src/installers/base.ts +0 -16
- package/cli/src/installers/cloud.ts +0 -127
- package/cli/src/installers/database.ts +0 -212
- package/cli/src/installers/docs.ts +0 -93
- package/cli/src/installers/email.ts +0 -119
- package/cli/src/installers/env-variables.ts +0 -27
- package/cli/src/installers/index.ts +0 -145
- package/cli/src/installers/observability.ts +0 -103
- package/cli/src/installers/queue.ts +0 -103
- package/cli/src/installers/ratelimit.ts +0 -98
- package/cli/src/installers/realtime.ts +0 -79
- package/cli/src/installers/testing.ts +0 -88
- package/cli/src/installers/validation.ts +0 -85
- package/cli/src/types/index.ts +0 -126
- package/cli/src/utils/add-package-dependency.ts +0 -56
- package/cli/src/utils/dependency-version-map.ts +0 -85
- package/cli/src/utils/logger.ts +0 -19
- package/cli/src/utils/parse-name-and-path.ts +0 -71
- package/cli/src/utils/render-title.ts +0 -11
- package/cli/tsconfig.json +0 -35
- package/test-cli.sh +0 -56
- package/tsconfig.json +0 -15
- /package/{cli/src → dist}/templates/base/.env.example +0 -0
- /package/{cli/src → dist}/templates/base/README.md +0 -0
- /package/{cli/src → dist}/templates/base/src/config/index.ts +0 -0
- /package/{cli/src → dist}/templates/base/src/index.ts +0 -0
- /package/{cli/src → dist}/templates/base/src/middleware/error.ts +0 -0
- /package/{cli/src → dist}/templates/base/src/middleware/logger.ts +0 -0
- /package/{cli/src → dist}/templates/base/src/utils/env.ts +0 -0
- /package/{cli/src → dist}/templates/base/tsconfig.json +0 -0
- /package/{cli/src → dist}/templates/base-bun-native/.env.example +0 -0
- /package/{cli/src → dist}/templates/base-bun-native/README.md +0 -0
- /package/{cli/src → dist}/templates/base-bun-native/src/config/index.ts +0 -0
- /package/{cli/src → dist}/templates/base-bun-native/src/middleware/error.ts +0 -0
- /package/{cli/src → dist}/templates/base-bun-native/src/middleware/logger.ts +0 -0
- /package/{cli/src → dist}/templates/base-bun-native/src/utils/env.ts +0 -0
- /package/{cli/src → dist}/templates/base-bun-native/tsconfig.json +0 -0
- /package/{cli/src → dist}/templates/base-express/.env.example +0 -0
- /package/{cli/src → dist}/templates/base-express/README.md +0 -0
- /package/{cli/src → dist}/templates/base-express/src/config/index.ts +0 -0
- /package/{cli/src → dist}/templates/base-express/src/index.ts +0 -0
- /package/{cli/src → dist}/templates/base-express/src/middleware/error.ts +0 -0
- /package/{cli/src → dist}/templates/base-express/src/middleware/logger.ts +0 -0
- /package/{cli/src → dist}/templates/base-express/src/utils/env.ts +0 -0
- /package/{cli/src → dist}/templates/base-express/tsconfig.json +0 -0
- /package/{cli/src → dist}/templates/extras/ai/anthropic/src/routes/ai/claude.ts +0 -0
- /package/{cli/src → dist}/templates/extras/ai/anthropic/src/services/ai/anthropic.ts +0 -0
- /package/{cli/src → dist}/templates/extras/ai/gemini/src/services/ai/gemini.ts +0 -0
- /package/{cli/src → dist}/templates/extras/ai/openai/src/routes/ai/chat.ts +0 -0
- /package/{cli/src → dist}/templates/extras/ai/openai/src/services/ai/openai.ts +0 -0
- /package/{cli/src → dist}/templates/extras/ai/vercel-ai/src/routes/ai/generate.ts +0 -0
- /package/{cli/src → dist}/templates/extras/ai/vercel-ai/src/routes/ai/stream.ts +0 -0
- /package/{cli/src → dist}/templates/extras/ai/vercel-ai/src/services/ai/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/auth/jwt/src/middleware/auth.ts +0 -0
- /package/{cli/src → dist}/templates/extras/auth/jwt/src/routes/auth.ts +0 -0
- /package/{cli/src → dist}/templates/extras/auth/jwt/src/utils/jwt.ts +0 -0
- /package/{cli/src → dist}/templates/extras/auth/oauth/src/config/oauth.ts +0 -0
- /package/{cli/src → dist}/templates/extras/auth/oauth/src/routes/auth.ts +0 -0
- /package/{cli/src → dist}/templates/extras/auth/session/src/config/session.ts +0 -0
- /package/{cli/src → dist}/templates/extras/auth/session/src/middleware/session.ts +0 -0
- /package/{cli/src → dist}/templates/extras/cloud/aws/src/services/aws/s3.ts +0 -0
- /package/{cli/src → dist}/templates/extras/cloud/aws/src/services/aws/ses.ts +0 -0
- /package/{cli/src → dist}/templates/extras/cloud/azure/src/services/azure/blob.ts +0 -0
- /package/{cli/src → dist}/templates/extras/cloud/cloudflare-r2/src/services/cloudflare/r2.ts +0 -0
- /package/{cli/src → dist}/templates/extras/cloud/gcp/src/services/gcp/storage.ts +0 -0
- /package/{cli/src → dist}/templates/extras/database/mongodb/src/db/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/database/mongodb/src/db/models/user.model.ts +0 -0
- /package/{cli/src → dist}/templates/extras/database/mysql/drizzle.config.ts +0 -0
- /package/{cli/src → dist}/templates/extras/database/postgres/src/db/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/database/redis/src/db/redis.ts +0 -0
- /package/{cli/src → dist}/templates/extras/docs/scalar/src/openapi/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/docs/scalar/src/routes/docs.ts +0 -0
- /package/{cli/src → dist}/templates/extras/docs/swagger/src/openapi/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/docs/swagger/src/routes/docs.ts +0 -0
- /package/{cli/src → dist}/templates/extras/email/nodemailer/src/services/email/nodemailer.ts +0 -0
- /package/{cli/src → dist}/templates/extras/email/resend/src/services/email/resend.ts +0 -0
- /package/{cli/src → dist}/templates/extras/email/resend/src/templates/email/welcome.ts +0 -0
- /package/{cli/src → dist}/templates/extras/email/sendgrid/src/services/email/sendgrid.ts +0 -0
- /package/{cli/src → dist}/templates/extras/observability/logtail/src/config/logger.ts +0 -0
- /package/{cli/src → dist}/templates/extras/observability/sentry/src/config/sentry.ts +0 -0
- /package/{cli/src → dist}/templates/extras/observability/sentry/src/middleware/sentry.ts +0 -0
- /package/{cli/src → dist}/templates/extras/queue/bullmq/src/queue/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/queue/bullmq/src/queue/jobs/email.job.ts +0 -0
- /package/{cli/src → dist}/templates/extras/queue/bullmq/src/queue/processors/email.processor.ts +0 -0
- /package/{cli/src → dist}/templates/extras/queue/bullmq/src/routes/queue.ts +0 -0
- /package/{cli/src → dist}/templates/extras/queue/inngest/src/inngest/client.ts +0 -0
- /package/{cli/src → dist}/templates/extras/queue/inngest/src/inngest/functions/email.ts +0 -0
- /package/{cli/src → dist}/templates/extras/queue/inngest/src/routes/inngest.ts +0 -0
- /package/{cli/src → dist}/templates/extras/realtime/socketio/src/socket/handlers.ts +0 -0
- /package/{cli/src → dist}/templates/extras/realtime/socketio/src/socket/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/realtime/sse/src/routes/sse.ts +0 -0
- /package/{cli/src → dist}/templates/extras/testing/vitest/src/__tests__/example.test.ts +0 -0
- /package/{cli/src → dist}/templates/extras/testing/vitest/src/__tests__/setup.ts +0 -0
- /package/{cli/src → dist}/templates/extras/testing/vitest/vitest.config.ts +0 -0
- /package/{cli/src → dist}/templates/extras/validation/yup/src/middleware/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/validation/yup/src/middleware/validate.ts +0 -0
- /package/{cli/src → dist}/templates/extras/validation/yup/src/routes/users.ts +0 -0
- /package/{cli/src → dist}/templates/extras/validation/zod/src/middleware/index.ts +0 -0
- /package/{cli/src → dist}/templates/extras/validation/zod/src/middleware/validate.ts +0 -0
- /package/{cli/src → dist}/templates/extras/validation/zod/src/routes/users.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/package.json +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/controllers/user/create-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/controllers/user/delete-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/controllers/user/get-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/controllers/user/get-users.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/controllers/user/update-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/models/user.model.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/routes/index.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/routes/user.route.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/types/common/api-response.types.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/types/index.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base/src/types/models/user.types.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/package.json +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/create-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/delete-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/get-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/get-users.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/update-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/index.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/models/user.model.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/routes/index.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/routes/user.route.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/types/common/api-response.types.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/types/index.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-bun-native/src/types/models/user.types.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/package.json +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/create-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/delete-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/get-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/get-users.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/update-user.controller.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/models/user.model.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/routes/index.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/routes/user.route.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/types/common/api-response.types.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/types/index.ts +0 -0
- /package/{cli/src → dist/templates}/templates/base-express/src/types/models/user.types.ts +0 -0
- /package/{prettier.config.mjs → dist/templates/templates/extras/ai/anthropic/src/routes/ai/claude.ts} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-backend-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-ready Bun backend with TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "bun --watch src/index.ts",
|
|
8
|
+
"start": "bun src/index.ts",
|
|
9
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
10
|
+
"type-check": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"hono": "^4.0.0",
|
|
14
|
+
"dotenv": "^16.3.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/bun": "latest",
|
|
18
|
+
"typescript": "^5.3.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-backend-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-ready backend with Bun native HTTP server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "bun --watch src/index.ts",
|
|
8
|
+
"start": "bun src/index.ts",
|
|
9
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
10
|
+
"type-check": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"dotenv": "^16.3.1"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/bun": "latest",
|
|
17
|
+
"typescript": "^5.3.3"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { config } from "./config/index.js";
|
|
2
|
+
import { logger } from "./middleware/logger.js";
|
|
3
|
+
import { errorHandler } from "./middleware/error.js";
|
|
4
|
+
import { router } from "./routes/index.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Simple router matcher for Bun native server
|
|
8
|
+
*/
|
|
9
|
+
function match_route(pathname: string, method: string): Response | null {
|
|
10
|
+
return router(pathname, method);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const server = Bun.serve({
|
|
14
|
+
port: config.port,
|
|
15
|
+
async fetch(req) {
|
|
16
|
+
const url = new URL(req.url);
|
|
17
|
+
const start = Date.now();
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
// Health check
|
|
21
|
+
if (url.pathname === "/health" && req.method === "GET") {
|
|
22
|
+
const response = Response.json({
|
|
23
|
+
status: "ok",
|
|
24
|
+
timestamp: new Date().toISOString(),
|
|
25
|
+
});
|
|
26
|
+
logger(req, response, Date.now() - start);
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Match routes
|
|
31
|
+
const response = match_route(url.pathname, req.method);
|
|
32
|
+
if (response) {
|
|
33
|
+
logger(req, response, Date.now() - start);
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 404 Not Found
|
|
38
|
+
const notFoundResponse = Response.json(
|
|
39
|
+
{ error: "Not Found" },
|
|
40
|
+
{ status: 404 }
|
|
41
|
+
);
|
|
42
|
+
logger(req, notFoundResponse, Date.now() - start);
|
|
43
|
+
return notFoundResponse;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return errorHandler(error, req);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log(`🚀 Server running on http://localhost:${server.port}`);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple router for Bun native server
|
|
3
|
+
* Add your routes here
|
|
4
|
+
*/
|
|
5
|
+
export function router(pathname: string, method: string): Response | null {
|
|
6
|
+
// GET /
|
|
7
|
+
if (pathname === "/" && method === "GET") {
|
|
8
|
+
return Response.json({
|
|
9
|
+
message: "Welcome to your Bun backend!",
|
|
10
|
+
docs: "/docs",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Add more routes here
|
|
15
|
+
// Example:
|
|
16
|
+
// if (pathname === "/users" && method === "GET") {
|
|
17
|
+
// return Response.json({ users: [] });
|
|
18
|
+
// }
|
|
19
|
+
|
|
20
|
+
return null; // No route matched
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-backend-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-ready backend with Express and TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "bun --watch src/index.ts",
|
|
8
|
+
"start": "bun src/index.ts",
|
|
9
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
10
|
+
"type-check": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"express": "^4.18.2",
|
|
14
|
+
"dotenv": "^16.3.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/bun": "latest",
|
|
18
|
+
"@types/express": "^4.17.21",
|
|
19
|
+
"typescript": "^5.3.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# My Backend App
|
|
2
|
+
|
|
3
|
+
Production-ready Bun backend with TypeScript and Hono.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
bun install
|
|
10
|
+
|
|
11
|
+
# Copy environment variables
|
|
12
|
+
cp .env.example .env
|
|
13
|
+
|
|
14
|
+
# Run development server
|
|
15
|
+
bun run dev
|
|
16
|
+
|
|
17
|
+
# Build for production
|
|
18
|
+
bun run build
|
|
19
|
+
|
|
20
|
+
# Run production server
|
|
21
|
+
bun run start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API Endpoints
|
|
25
|
+
|
|
26
|
+
- `GET /` - Welcome message
|
|
27
|
+
- `GET /health` - Health check
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
Visit `/docs` for API documentation (if Swagger/Scalar is installed).
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { logger as loggerMiddleware } from "./middleware/logger.js";
|
|
3
|
+
import { errorHandler } from "./middleware/error.js";
|
|
4
|
+
import routes from "./routes/index.js";
|
|
5
|
+
import { config } from "./config/index.js";
|
|
6
|
+
|
|
7
|
+
const app = new Hono();
|
|
8
|
+
|
|
9
|
+
// Middleware
|
|
10
|
+
app.use("*", loggerMiddleware);
|
|
11
|
+
app.onError(errorHandler);
|
|
12
|
+
|
|
13
|
+
// Routes
|
|
14
|
+
app.route("/", routes);
|
|
15
|
+
|
|
16
|
+
// Health check
|
|
17
|
+
app.get("/health", (c) => {
|
|
18
|
+
return c.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log(`🚀 Server running on http://localhost:${config.port}`);
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
port: config.port,
|
|
25
|
+
fetch: app.fetch,
|
|
26
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ErrorHandler } from "hono";
|
|
2
|
+
|
|
3
|
+
export const errorHandler: ErrorHandler = (err, c) => {
|
|
4
|
+
console.error(`Error: ${err.message}`, err);
|
|
5
|
+
|
|
6
|
+
return c.json(
|
|
7
|
+
{
|
|
8
|
+
error: err.message || "Internal Server Error",
|
|
9
|
+
status: err.status || 500,
|
|
10
|
+
},
|
|
11
|
+
err.status || 500
|
|
12
|
+
);
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from "hono";
|
|
2
|
+
|
|
3
|
+
export const logger: MiddlewareHandler = async (c, next) => {
|
|
4
|
+
const start = Date.now();
|
|
5
|
+
await next();
|
|
6
|
+
const ms = Date.now() - start;
|
|
7
|
+
console.log(`${c.req.method} ${c.req.url} - ${c.res.status} (${ms}ms)`);
|
|
8
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ESNext"],
|
|
7
|
+
"types": ["bun-types"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"outDir": "./dist",
|
|
16
|
+
"rootDir": "./src"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist"]
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# My Backend App
|
|
2
|
+
|
|
3
|
+
Production-ready Bun backend with TypeScript and Hono.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
bun install
|
|
10
|
+
|
|
11
|
+
# Copy environment variables
|
|
12
|
+
cp .env.example .env
|
|
13
|
+
|
|
14
|
+
# Run development server
|
|
15
|
+
bun run dev
|
|
16
|
+
|
|
17
|
+
# Build for production
|
|
18
|
+
bun run build
|
|
19
|
+
|
|
20
|
+
# Run production server
|
|
21
|
+
bun run start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API Endpoints
|
|
25
|
+
|
|
26
|
+
- `GET /` - Welcome message
|
|
27
|
+
- `GET /health` - Health check
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
Visit `/docs` for API documentation (if Swagger/Scalar is installed).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handler for Bun native server
|
|
3
|
+
*/
|
|
4
|
+
export function errorHandler(error: unknown, req: Request): Response {
|
|
5
|
+
console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`, error);
|
|
6
|
+
|
|
7
|
+
const status = error instanceof Error && "status" in error
|
|
8
|
+
? (error as Error & { status: number }).status
|
|
9
|
+
: 500;
|
|
10
|
+
|
|
11
|
+
const message = error instanceof Error ? error.message : "Internal Server Error";
|
|
12
|
+
|
|
13
|
+
return Response.json(
|
|
14
|
+
{
|
|
15
|
+
error: message,
|
|
16
|
+
status,
|
|
17
|
+
},
|
|
18
|
+
{ status }
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ESNext"],
|
|
7
|
+
"types": ["bun-types"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"outDir": "./dist",
|
|
16
|
+
"rootDir": "./src"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist"]
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# My Backend App
|
|
2
|
+
|
|
3
|
+
Production-ready Bun backend with TypeScript and Hono.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
bun install
|
|
10
|
+
|
|
11
|
+
# Copy environment variables
|
|
12
|
+
cp .env.example .env
|
|
13
|
+
|
|
14
|
+
# Run development server
|
|
15
|
+
bun run dev
|
|
16
|
+
|
|
17
|
+
# Build for production
|
|
18
|
+
bun run build
|
|
19
|
+
|
|
20
|
+
# Run production server
|
|
21
|
+
bun run start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API Endpoints
|
|
25
|
+
|
|
26
|
+
- `GET /` - Welcome message
|
|
27
|
+
- `GET /health` - Health check
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
Visit `/docs` for API documentation (if Swagger/Scalar is installed).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { logger as loggerMiddleware } from "./middleware/logger.js";
|
|
3
|
+
import { errorHandler } from "./middleware/error.js";
|
|
4
|
+
import routes from "./routes/index.js";
|
|
5
|
+
import { config } from "./config/index.js";
|
|
6
|
+
|
|
7
|
+
const app = express();
|
|
8
|
+
|
|
9
|
+
// Middleware
|
|
10
|
+
app.use(express.json());
|
|
11
|
+
app.use(express.urlencoded({ extended: true }));
|
|
12
|
+
app.use(loggerMiddleware);
|
|
13
|
+
|
|
14
|
+
// Routes
|
|
15
|
+
app.use("/", routes);
|
|
16
|
+
|
|
17
|
+
// Health check
|
|
18
|
+
app.get("/health", (req, res) => {
|
|
19
|
+
res.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Error handler (must be last)
|
|
23
|
+
app.use(errorHandler);
|
|
24
|
+
|
|
25
|
+
app.listen(config.port, () => {
|
|
26
|
+
console.log(`🚀 Server running on http://localhost:${config.port}`);
|
|
27
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
|
|
3
|
+
export const errorHandler = (
|
|
4
|
+
err: Error & { status?: number },
|
|
5
|
+
req: Request,
|
|
6
|
+
res: Response,
|
|
7
|
+
next: NextFunction
|
|
8
|
+
) => {
|
|
9
|
+
console.error(`Error: ${err.message}`, err);
|
|
10
|
+
|
|
11
|
+
res.status(err.status || 500).json({
|
|
12
|
+
error: err.message || "Internal Server Error",
|
|
13
|
+
status: err.status || 500,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
|
|
3
|
+
export const logger = (req: Request, res: Response, next: NextFunction) => {
|
|
4
|
+
const start = Date.now();
|
|
5
|
+
|
|
6
|
+
res.on("finish", () => {
|
|
7
|
+
const ms = Date.now() - start;
|
|
8
|
+
console.log(`${req.method} ${req.url} - ${res.statusCode} (${ms}ms)`);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
next();
|
|
12
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ESNext"],
|
|
7
|
+
"types": ["bun-types"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"outDir": "./dist",
|
|
16
|
+
"rootDir": "./src"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist"]
|
|
20
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|