0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-22 08:58:11 +00:00

dev base (kinda stable)

This commit is contained in:
Víctor Losada Hernández
2026-01-30 12:41:14 +01:00
parent 86f3d5c290
commit 20678ba420
10 changed files with 755 additions and 564 deletions

View File

@@ -1,20 +1,47 @@
import DB from './server/db.js';
import server from './server/app.js';
import config from './server/config.js';
import DB from "./server/db.js";
import createApp from "./server/app.js";
import config from "./server/config.js";
import { createServer as createViteServer } from "vite";
DB.connect(config).then(()=>{
// Ensure that we have successfully connected to the database
// before launching server
const PORT = process.env.PORT || config.get('web_port') || 8000;
server.listen(PORT, ()=>{
const reset = '\x1b[0m'; // Reset to default style
const bright = '\x1b[1m'; // Bright (bold) style
const cyan = '\x1b[36m'; // Cyan color
const underline = '\x1b[4m'; // Underlined style
const isProd = process.env.NODE_ENV === "production";
async function start() {
let vite;
//==== Create Vite dev server only in development ====//
if (!isProd) {
vite = await createViteServer({
server: { middlewareMode: true },
appType: "custom",
logLevel: 'error',
});
}
//==== Connect to the database ====//
await DB.connect(config).catch((err) => {
console.error("Database connection failed:", err);
process.exit(1);
});
//==== Create the Express app ====//
const app = await createApp(vite);
//==== Start listening ====//
const PORT = process.env.PORT || config.get("web_port") || 8000;
app.listen(PORT, () => {
const reset = "\x1b[0m"; // Reset to default style
const bright = "\x1b[1m"; // Bright (bold) style
const cyan = "\x1b[36m"; // Cyan color
const underline = "\x1b[4m"; // Underlined style
console.log(`\n\tserver started at: ${new Date().toLocaleString()}`);
console.log(`\tserver on port: ${PORT}`);
console.log(`\t${bright + cyan}Open in browser: ${reset}${underline + bright + cyan}http://localhost:${PORT}${reset}\n\n`);
console.log(
`\t${bright + cyan}Open in browser: ${reset}${underline + bright + cyan}http://localhost:${PORT}${reset}\n\n`,
);
});
});
}
//==== Start the server ====//
start();