feat(deploy): production deployment setup and fixes
- Debian-based api image (bookworm-slim), docker/debian mirrors, prisma binaryTargets for openssl 3.0 - nginx: admin SPA under /admin, TLS via acme.sh (ZeroSSL) + auto-renewal cron, http->https redirect - prisma: add origin_goods.delisted migration, sync missing schema (good_image/tag_font_color/good_tags), fix users.createdAt Timestamptz - api: CORS wildcard reflection, helmet CORP cross-origin, price backfill in persistProductDetail, categoryIcon ancestor fallback, mediaByColor per-color gallery in public goods detail - admin: /admin base path (vite + router) - import-data.mjs: udt_name casting, serial sequence advance fix
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Set the admin credentials for the production deployment:
|
||||
* rename/disable any existing admin and create/update user `inkreach`.
|
||||
*
|
||||
* Usage (inside the api container): node scripts/set-admin.mjs
|
||||
* Reads NEW_ADMIN_USER / NEW_ADMIN_PASSWORD from env.
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const username = process.env.NEW_ADMIN_USER;
|
||||
const password = process.env.NEW_ADMIN_PASSWORD;
|
||||
if (!username || !password) {
|
||||
console.error('NEW_ADMIN_USER / NEW_ADMIN_PASSWORD must be set');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const passwordHash = await bcrypt.hash(password, 10);
|
||||
await prisma.user.upsert({
|
||||
where: { username },
|
||||
create: { username, passwordHash },
|
||||
update: { passwordHash, tokenVersion: { increment: 1 } },
|
||||
});
|
||||
|
||||
// Remove every other admin so only `inkreach` can sign in.
|
||||
const others = await prisma.user.deleteMany({
|
||||
where: { username: { not: username } },
|
||||
});
|
||||
|
||||
const total = await prisma.user.count();
|
||||
console.log(`Admin '${username}' set. Demoted ${others.count} other user(s). Total users: ${total}.`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(() => prisma.$disconnect());
|
||||
Reference in New Issue
Block a user