Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions template/apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
# should be updated accordingly.

# If you are using Docker for the development process,
# you need to use the following variables for MongoDB and Redis:
# MONGO_URI=mongodb://root:root@mongo/api-development?authSource=admin&replicaSet=rs
# you need to use the following variables for PostgreSQL and Redis:
# DATABASE_URL=postgresql://root:root@postgres:5432/api-development
# REDIS_URI=redis://:@redis:6379

# MongoDB
MONGO_URI=mongodb://root:root@localhost:27017/api-development?authSource=admin&replicaSet=rs&tls=false&directConnection=true
MONGO_DB_NAME=api-development
# PostgreSQL
DATABASE_URL=postgresql://root:root@localhost:5432/api-development

# Redis
REDIS_URI=redis://:@localhost:6379
Expand Down
3 changes: 0 additions & 3 deletions template/apps/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ yarn-error.log*

# typescript
*.tsbuildinfo

# auto-generated
src/db.ts
11 changes: 11 additions & 0 deletions template/apps/api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'drizzle-kit';
import process from 'node:process';

export default defineConfig({
dialect: 'postgresql',
schema: './src/resources/*/*.schema.ts',
out: './drizzle',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});
12 changes: 8 additions & 4 deletions template/apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
"build": "pnpm codegen && tsc",
"build:types": "pnpm codegen && tsc --emitDeclarationOnly",
"dev": "tsx scripts/codegen-router.ts --watch & NODE_ENV=development APP_ENV=development tsx watch --clear-screen=false --env-file=.env src/app.ts",
"codegen": "tsx scripts/codegen-db-types.ts && tsx scripts/codegen-router.ts && eslint --fix src/router.ts src/db.ts && prettier --write src/router.ts src/db.ts",
"codegen": "tsx scripts/codegen-router.ts && eslint --fix src/router.ts && prettier --write src/router.ts",
"start": "NODE_ENV=development APP_ENV=development tsx --env-file=.env src/app.ts",
"migrate-dev": "NODE_ENV=development APP_ENV=development tsx --env-file=.env src/migrator.ts",
"migrate": "tsx src/migrator.ts",
"migrate": "NODE_ENV=development APP_ENV=development tsx --env-file=.env -e 'import {migrate} from \"drizzle-orm/postgres-js/migrator\"; import {rawDb as db} from \"./src/db\"; await migrate(db, {migrationsFolder: \"./drizzle\"}); process.exit(0);'",
"generate": "drizzle-kit generate",
"db:push": "drizzle-kit push",
"schedule-dev": "NODE_ENV=development APP_ENV=development tsx watch --env-file=.env src/scheduler.ts",
"schedule": "tsx src/scheduler.ts",
"tsc": "tsc --noEmit --watch",
Expand All @@ -33,18 +34,19 @@
"@orpc/server": "^1.5.0",
"@oslojs/crypto": "1.0.1",
"@oslojs/encoding": "1.1.0",
"@paralect/node-mongo": "link:../../../packages/node-mongo",
"@socket.io/redis-adapter": "8.3.0",
"@socket.io/redis-emitter": "5.1.0",
"app-constants": "workspace:*",
"arctic": "3.7.0",
"dayjs": "1.11.13",
"drizzle-orm": "1.0.0-beta.19",
"hono": "^4.7.0",
"ioredis": "5.6.1",
"lodash": "4.17.21",
"mailer": "workspace:*",
"mixpanel": "0.18.1",
"node-schedule": "2.1.1",
"postgres": "3.4.8",
"resend": "4.5.2",
"socket.io": "4.8.1",
"tldts": "7.0.8",
Expand All @@ -55,8 +57,10 @@
"@types/lodash": "4.17.17",
"@types/node": "catalog:",
"@types/node-schedule": "2.1.7",
"drizzle-kit": "1.0.0-beta.19",
"eslint": "catalog:",
"eslint-config": "workspace:*",
"i": "0.3.7",
"lint-staged": "catalog:",
"prettier": "catalog:",
"prettier-config": "workspace:*",
Expand Down
75 changes: 0 additions & 75 deletions template/apps/api/scripts/codegen-db-types.ts

This file was deleted.

11 changes: 4 additions & 7 deletions template/apps/api/src/admin-set.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import process from 'node:process';

import init from '@/init-db';
import db from '@/db';
import logger from '@/logger';
import { emailSchema } from '@/resources/base.schema';
import { emailSchema } from '@/resources/users/users.schema';

const usage = 'Usage: pnpm admin:set -- <email>';

Expand All @@ -16,10 +16,7 @@ const main = async () => {

const email = emailSchema.parse(rawEmail);

await init();

const { usersService } = await import('@/db');
const user = await usersService.findOne({ email });
const user = await db.users.findFirst({ where: { email } });

if (!user) {
throw new Error(`User not found: ${email}`);
Expand All @@ -30,7 +27,7 @@ const main = async () => {
return;
}

await usersService.updateOne({ _id: user._id }, () => ({ isAdmin: true }));
await db.users.updateOne({ id: user.id }, { isAdmin: true });

logger.info(`User ${email} was promoted to admin.`);
};
Expand Down
5 changes: 2 additions & 3 deletions template/apps/api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable antfu/no-top-level-await */
import init from '@/init-db';

await init();
import './resources/users/handlers/sync-analytics';
import './resources/users/handlers/to-sockets';

const { default: app } = await import('server');

Expand Down
3 changes: 1 addition & 2 deletions template/apps/api/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const schema = z.object({
PORT: z.coerce.number().optional().default(3001),
API_URL: z.string(),
WEB_URL: z.string(),
MONGO_URI: z.string(),
MONGO_DB_NAME: z.string(),
DATABASE_URL: z.string(),
REDIS_URI: z.string().optional(),
REDIS_ERRORS_POLICY: z.enum(['throw', 'log']).default('log'),
RESEND_API_KEY: z.string().optional(),
Expand Down
Loading