init push
This commit is contained in:
30
backend/server.js
Normal file
30
backend/server.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import recipesRouter from './routes/recipes.js';
|
||||
import authRouter from './routes/auth.js';
|
||||
import { getUserByUsername, createUser } from './db.js';
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3001;
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
app.use('/api/auth', authRouter);
|
||||
app.use('/api/recipes', recipesRouter);
|
||||
|
||||
const adminUser = process.env.ADMIN_USER || 'admin';
|
||||
const adminPass = process.env.ADMIN_PASS || 'admin123';
|
||||
|
||||
const existing = getUserByUsername(adminUser);
|
||||
if (!existing) {
|
||||
const hashed = bcrypt.hashSync(adminPass, 10);
|
||||
createUser(adminUser, hashed, true);
|
||||
console.log(`Admin erstellt: ${adminUser} / ${adminPass}`);
|
||||
console.log('WICHTIG: Passwort nach dem ersten Login ändern!');
|
||||
}
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Backend läuft auf http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user