feat: initial project structure — Express/TS/TypeORM + React/TS + Docker + Gitea CI
This commit is contained in:
16
backend/src/config/data-source.ts
Normal file
16
backend/src/config/data-source.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import "reflect-metadata";
|
||||
import { DataSource } from "typeorm";
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
type: "mysql",
|
||||
host: process.env.DB_HOST ?? "mysql",
|
||||
port: parseInt(process.env.DB_PORT ?? "3306"),
|
||||
username: process.env.DB_USER ?? "originsdigital",
|
||||
password: process.env.DB_PASSWORD ?? "",
|
||||
database: process.env.DB_NAME ?? "originsdigital",
|
||||
synchronize: false,
|
||||
logging: process.env.NODE_ENV === "development",
|
||||
entities: ["src/entities/**/*.ts"],
|
||||
migrations: ["src/migrations/**/*.ts"],
|
||||
subscribers: [],
|
||||
});
|
||||
29
backend/src/index.ts
Normal file
29
backend/src/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import "reflect-metadata";
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import dotenv from "dotenv";
|
||||
import { AppDataSource } from "./config/data-source";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
const PORT = parseInt(process.env.PORT ?? "4000");
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
app.get("/api/health", (_req, res) => {
|
||||
res.json({ status: "ok", timestamp: new Date().toISOString() });
|
||||
});
|
||||
|
||||
AppDataSource.initialize()
|
||||
.then(() => {
|
||||
console.log("Database connected");
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on port ${PORT}`);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Database connection failed:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user