Enhance Next.js configuration and dependencies for improved functionality and localization support. Added support for internationalization with next-intl, updated global styles, and integrated new fonts. Removed default home page and updated README with project details and setup instructions.
This commit is contained in:
1 parent
2911dea00b
commit
44f4fa98e2
320 files changed
+31666
-220
No files matched your search
@@ -0,0 +1,56 @@
|
||||
// Quick admin user seed for Phase E - standalone .mjs
|
||||
import { randomBytes, scrypt } from "node:crypto";
|
||||
import { promisify } from "node:util";
|
||||
import pg from "pg";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
|
||||
const scryptAsync = promisify(scrypt);
|
||||
|
||||
async function hashPassword(password) {
|
||||
const salt = randomBytes(16);
|
||||
const derived = await scryptAsync(password, salt, 64);
|
||||
return `${salt.toString("hex")}:${derived.toString("hex")}`;
|
||||
}
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
const envPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", ".env.local");
|
||||
if (existsSync(envPath)) {
|
||||
for (const line of readFileSync(envPath, "utf8").split(/\r?\n/)) {
|
||||
const match = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (match && !(match[1] in process.env)) {
|
||||
process.env[match[1]] = match[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const { Pool } = pg;
|
||||
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
||||
|
||||
async function main() {
|
||||
const email = "admin@aut.ac.ir";
|
||||
const password = "admin123";
|
||||
const name = "مدیر سیستم";
|
||||
const role = "admin";
|
||||
|
||||
const passwordHash = await hashPassword(password);
|
||||
|
||||
try {
|
||||
await pool.query(
|
||||
`INSERT INTO admin_users (email, password_hash, name, role)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (email) DO UPDATE SET password_hash = $2, name = $3, role = $4`,
|
||||
[email, passwordHash, name, role],
|
||||
);
|
||||
console.log("Admin user seeded:", email, "/", password);
|
||||
} catch (error) {
|
||||
console.error("Seed admin error:", error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
await main();
|
||||
@@ -0,0 +1,92 @@
|
||||
// Phase H — smoke test: public read APIs + one authenticated admin write.
|
||||
// Usage: node scripts/smoke.mjs (server must already be running)
|
||||
// SMOKE_BASE_URL=http://localhost:3000 node scripts/smoke.mjs
|
||||
// SMOKE_ADMIN_EMAIL / SMOKE_ADMIN_PASSWORD to override the test admin.
|
||||
// Exits non-zero on the first failed assertion and leaves no data behind.
|
||||
|
||||
const BASE = process.env.SMOKE_BASE_URL ?? "http://localhost:3100";
|
||||
const ADMIN_EMAIL = process.env.SMOKE_ADMIN_EMAIL ?? "";
|
||||
const ADMIN_PASSWORD = process.env.SMOKE_ADMIN_PASSWORD ?? "";
|
||||
const ADMIN_API = `${BASE}/api/admin`;
|
||||
|
||||
let failures = 0;
|
||||
function check(name, ok, detail = "") {
|
||||
if (ok) {
|
||||
console.log(` PASS ${name}`);
|
||||
} else {
|
||||
failures += 1;
|
||||
console.error(` FAIL ${name}${detail ? ` — ${detail}` : ""}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function readJson(res) {
|
||||
const text = await res.text();
|
||||
const json = text ? JSON.parse(text) : {};
|
||||
return { status: res.status, json };
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log(`Smoke: ${BASE}`);
|
||||
|
||||
for (const path of ["courses", "programs", "events", "articles"]) {
|
||||
const res = await fetch(`${BASE}/api/${path}`);
|
||||
const { status, json } = await readJson(res);
|
||||
check(`GET /api/${path}`, status === 200 && Array.isArray(json.data), `status=${status}`);
|
||||
}
|
||||
|
||||
if (!ADMIN_EMAIL || !ADMIN_PASSWORD) {
|
||||
console.error("\nSMOKE_ADMIN_EMAIL / SMOKE_ADMIN_PASSWORD are required for the admin write test.");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const loginRes = await fetch(`${ADMIN_API}/login`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ email: ADMIN_EMAIL, password: ADMIN_PASSWORD }),
|
||||
});
|
||||
const { status: loginStatus, json: loginJson } = await readJson(loginRes);
|
||||
check("POST /api/admin/login", loginStatus === 200 && loginJson.ok, `status=${loginStatus}`);
|
||||
if (loginStatus !== 200) {
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const setCookie = loginRes.headers.get("set-cookie") ?? "";
|
||||
const cookieMatch = setCookie.match(/admin_session=([^;]+)/);
|
||||
if (!cookieMatch) {
|
||||
check("login set-cookie present", false, "no admin_session cookie header");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
const cookie = `admin_session=${cookieMatch[1]}`;
|
||||
const authHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
Cookie: cookie,
|
||||
};
|
||||
|
||||
const createRes = await fetch(`${ADMIN_API}/stats`, {
|
||||
method: "POST",
|
||||
headers: authHeaders,
|
||||
body: JSON.stringify({ value: "1", label: "__smoke_test__" }),
|
||||
});
|
||||
const { status: createStatus, json: createJson } = await readJson(createRes);
|
||||
const statId = createJson?.data?.id ?? "";
|
||||
check("POST /api/admin/stats (create)", createStatus === 201 && statId, `status=${createStatus}`);
|
||||
if (createStatus !== 201 || !statId) {
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const delRes = await fetch(`${ADMIN_API}/stats/${statId}`, {
|
||||
method: "DELETE",
|
||||
headers: authHeaders,
|
||||
});
|
||||
const { status: delStatus } = await readJson(delRes);
|
||||
check(`DELETE /api/admin/stats/${statId}`, delStatus === 200, `status=${delStatus}`);
|
||||
|
||||
console.log(failures === 0 ? "\nSMOKE_OK" : `\nSMOKE_FAIL (${failures})`);
|
||||
process.exitCode = failures === 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
await main();
|
||||
@@ -0,0 +1,42 @@
|
||||
import pg from "pg";
|
||||
|
||||
const { Client } = pg;
|
||||
|
||||
const client = new Client({
|
||||
host: "138.124.117.71",
|
||||
port: 5432,
|
||||
database: "ManagmentWebSite_Db",
|
||||
user: "managment_web",
|
||||
password: "hD3H9seTqX1GJMu1mDJBGDYr",
|
||||
connectionTimeoutMillis: 20000,
|
||||
});
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
const info = await client.query(`
|
||||
SELECT
|
||||
version() AS version,
|
||||
current_database() AS database,
|
||||
current_user AS username,
|
||||
pg_encoding_to_char(encoding) AS encoding
|
||||
FROM pg_database
|
||||
WHERE datname = current_database()
|
||||
`);
|
||||
console.log("CONNECTION_OK");
|
||||
console.log(JSON.stringify(info.rows[0], null, 2));
|
||||
|
||||
const tables = await client.query(`
|
||||
SELECT table_schema, table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
|
||||
ORDER BY 1, 2
|
||||
`);
|
||||
console.log("tables_count:", tables.rows.length);
|
||||
console.log(JSON.stringify(tables.rows, null, 2));
|
||||
} catch (error) {
|
||||
console.error("CONNECTION_FAIL");
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
await client.end().catch(() => {});
|
||||
}
|
||||
Reference in new issue
Block a user