This repository has been archived on 2026-05-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Nest/nest-backend/src/index.ts

37 lines
980 B
TypeScript

import 'dotenv/config';
import bcrypt from 'bcryptjs';
import prisma from './lib/prisma.js';
import app from './app.js';
const PORT = parseInt(process.env.PORT ?? '3000', 10);
async function ensureAdmin(): Promise<void> {
const { ADMIN_USERNAME, ADMIN_EMAIL, ADMIN_PASSWORD } = process.env;
if (!ADMIN_USERNAME || !ADMIN_EMAIL || !ADMIN_PASSWORD) return;
await prisma.user.upsert({
where: { email: ADMIN_EMAIL },
update: { username: ADMIN_USERNAME, role: 'dev', isAdmin: true },
create: {
username: ADMIN_USERNAME,
email: ADMIN_EMAIL,
password: await bcrypt.hash(ADMIN_PASSWORD, 10),
role: 'dev',
isAdmin: true,
},
});
console.log(`[server] Admin user ready: ${ADMIN_USERNAME}`);
}
ensureAdmin()
.then(() => {
app.listen(PORT, () => {
console.log(`[server] Running on http://localhost:${PORT}`);
});
})
.catch((err) => {
console.error('[server] Startup error:', err);
process.exit(1);
});