mirror of
https://github.com/gnmyt/LicenseAPI.git
synced 2026-01-09 17:51:47 +00:00
Implement projectVersion in server.ts
This commit is contained in:
@ -5,6 +5,7 @@ import { sendError } from "@utils/error";
|
|||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import env from "./templates/env";
|
import env from "./templates/env";
|
||||||
|
import packageJson from "../package.json";
|
||||||
|
|
||||||
const MONGOOSE_STRING = process.env.MONGOOSE_STRING || "mongodb://localhost:27017";
|
const MONGOOSE_STRING = process.env.MONGOOSE_STRING || "mongodb://localhost:27017";
|
||||||
|
|
||||||
@ -12,6 +13,8 @@ const app: Application = express();
|
|||||||
const port: number = parseInt(process.env.SERVER_PORT || "8025");
|
const port: number = parseInt(process.env.SERVER_PORT || "8025");
|
||||||
const isDevelopment: boolean = process.env.NODE_ENV !== "production";
|
const isDevelopment: boolean = process.env.NODE_ENV !== "production";
|
||||||
|
|
||||||
|
process.env.PROJECT_VERSION = isDevelopment ? "DEV" : packageJson.version;
|
||||||
|
|
||||||
// Configure backend
|
// Configure backend
|
||||||
app.disable("x-powered-by");
|
app.disable("x-powered-by");
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@ -24,7 +27,7 @@ app.use("/api/v1/", v1Router);
|
|||||||
|
|
||||||
app.use("/api/*", (_req: Request, res: Response) => sendError(res, 404, 0, "The provided route could not be found"));
|
app.use("/api/*", (_req: Request, res: Response) => sendError(res, 404, 0, "The provided route could not be found"));
|
||||||
|
|
||||||
if (process.env.NODE_ENV === "production") {
|
if (!isDevelopment) {
|
||||||
app.use(express.static(path.join(__dirname, "../build")));
|
app.use(express.static(path.join(__dirname, "../build")));
|
||||||
|
|
||||||
app.get("*", (_req, res) => res.sendFile(path.join(__dirname, "../build", "index.html")));
|
app.get("*", (_req, res) => res.sendFile(path.join(__dirname, "../build", "index.html")));
|
||||||
|
|||||||
Reference in New Issue
Block a user