Add environment variable for API URL; update TypeScript configuration to include vite-env; refactor API client to use environment variable; modify timestamp fields in database schemas to include timezone support
This commit is contained in:
@@ -0,0 +1 @@
|
||||
VITE_API_URL=http://localhost:3000
|
||||
@@ -2,7 +2,7 @@ import ky from "ky";
|
||||
|
||||
// Базовый API клиент
|
||||
export const api = ky.create({
|
||||
prefixUrl: "http://localhost:3000",
|
||||
prefixUrl: import.meta.env.VITE_API_URL,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
@@ -11,6 +11,7 @@ export const api = ky.create({
|
||||
(request) => {
|
||||
// Автоматически добавляем токен из localStorage если есть
|
||||
const token = localStorage.getItem("authToken");
|
||||
|
||||
if (token) {
|
||||
request.headers.set("Authorization", `Bearer ${token}`);
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
"include": ["src", "vite-env.d.ts"]
|
||||
}
|
||||
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_API_URL: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
@@ -15,8 +15,12 @@ export const apps = pgTable("apps", {
|
||||
title: varchar("title").notNull(), // Название приложения (например, "Майнкрафт")
|
||||
gpuLimitMb: integer("gpu_limit_mb"), // Лимит GPU в мегабайтах (только для stream серверов)
|
||||
psVersion: integer("ps_version"), // Версия Pixel Streaming (например, "1")
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
// Zod schemas for validation
|
||||
|
||||
@@ -11,8 +11,12 @@ export const branches = pgTable("branches", {
|
||||
address: varchar("address", { length: 500 }),
|
||||
city: varchar("city", { length: 100 }),
|
||||
country: varchar("country", { length: 100 }),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
// Zod schemas for validation
|
||||
|
||||
@@ -5,8 +5,12 @@ export const companies = pgTable("companies", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
name: varchar("name", { length: 255 }).notNull(),
|
||||
description: varchar("description", { length: 1000 }),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
// Zod schemas for validation
|
||||
|
||||
@@ -31,8 +31,12 @@ export const serverSessions = pgTable("server_sessions", {
|
||||
cirrusPid: integer("cirrus_pid"),
|
||||
mode: sessionModeEnum("mode").notNull(), // stream, local
|
||||
status: sessionStatusEnum("status").notNull(), // starting, started, ending, ended
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { pgTable, uuid, varchar, pgEnum } from "drizzle-orm/pg-core";
|
||||
import { pgTable, uuid, varchar, pgEnum, timestamp } from "drizzle-orm/pg-core";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
||||
import { serverSessions } from "./serverSessions";
|
||||
import { branches } from "./branches";
|
||||
|
||||
// Enums
|
||||
export const serverLocationEnum = pgEnum("server_location", ["ru1", "uae1"]);
|
||||
@@ -11,10 +12,17 @@ export const serverTierEnum = pgEnum("server_tier", ["demo", "prod"]);
|
||||
export const servers = pgTable("servers", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
localIp: varchar("local_ip", { length: 45 }).notNull(), // IPv6 can be up to 45 chars
|
||||
hostname: varchar("hostname").notNull(),
|
||||
hostname: varchar("hostname").notNull(), // hostname сервера
|
||||
type: serverTypeEnum("type").notNull(), // stream, local
|
||||
branchId: uuid("branch_id").references(() => branches.id), // филиал, на котором находится сервер (nullable для локальных серверов)
|
||||
location: serverLocationEnum("location"), // ru1, uae1 (только для stream)
|
||||
tier: serverTierEnum("tier"), // demo, prod (только для stream)
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
// Zod schemas for validation
|
||||
|
||||
@@ -14,7 +14,9 @@ export const userBranches = pgTable(
|
||||
branchId: uuid("branch_id")
|
||||
.notNull()
|
||||
.references(() => branches.id, { onDelete: "cascade" }),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
pk: primaryKey({ columns: [table.userId, table.branchId] }),
|
||||
|
||||
Reference in New Issue
Block a user