Skip to content

Commit f299b3a

Browse files
committed
feat: Permite configuração da porta via variável de ambiente e adiciona autenticação
1 parent ec6a453 commit f299b3a

File tree

3 files changed

+53
-30
lines changed

3 files changed

+53
-30
lines changed

demo/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ bun run start
1212

1313
## Acessar
1414

15-
- **Página inicial:** http://localhost:3000
16-
- **Painel Admin:** http://localhost:3000/sqlite
15+
- **Página inicial:** http://localhost:3099
16+
- **Painel Admin:** http://localhost:3099/sqlite
1717

1818
## Banco de Dados
1919

demo/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,11 @@ const app = new Elysia()
283283
// Plugin SQLite
284284
.use(sqliteAdmin({ dbPath: DB_PATH, prefix: "/sqlite" }))
285285

286-
.listen(3000);
286+
.listen(process.env.PORT || 3000);
287287

288-
console.log("🚀 Demo rodando em: http://localhost:3000");
289-
console.log("📊 Painel Admin em: http://localhost:3000/sqlite\n");
288+
const port = process.env.PORT || 3000;
289+
console.log(`🚀 Demo rodando em: http://localhost:${port}`);
290+
console.log(`📊 Painel Admin em: http://localhost:${port}/sqlite\n`);
290291
console.log("💡 Dica: Experimente consultas SQL como:");
291292
console.log(" SELECT * FROM clientes");
292293
console.log(" SELECT * FROM produtos WHERE preco > 5000");

src/ui/src/App.jsx

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import { DataGrid } from "./components/DataGrid";
8383
import { Pagination } from "./components/Pagination";
8484

8585
const API = "/sqlite/api";
86+
const AUTH = "/sqlite/auth";
8687

8788
// Column type icon mapping
8889
const getColumnIcon = (type, name) => {
@@ -126,7 +127,7 @@ const NewRecordModal = ({
126127
currentTable,
127128
onSuccess,
128129
}) => {
129-
// ... (modal implementation)
130+
// ... (modal implementation)
130131
const [formData, setFormData] = useState({});
131132
const [fkOptionsMap, setFkOptionsMap] = useState({});
132133
const [loadingFk, setLoadingFk] = useState({});
@@ -267,7 +268,6 @@ const NewRecordModal = ({
267268
);
268269
};
269270

270-
271271
export default function App() {
272272
const { colorScheme, toggleColorScheme } = useMantineColorScheme();
273273
const dark = colorScheme === "dark";
@@ -276,12 +276,13 @@ export default function App() {
276276
const [auth, setAuth] = useState(null);
277277

278278
// Security Modal
279-
const [securityOpened, { open: openSecurity, close: closeSecurity }] = useDisclosure(false);
280-
279+
const [securityOpened, { open: openSecurity, close: closeSecurity }] =
280+
useDisclosure(false);
281+
281282
// ... (rest of checkAuth and useEffect)
282283
const checkAuth = async () => {
283284
try {
284-
const res = await fetch("/sqlite/auth/status");
285+
const res = await fetch(`${AUTH}/status`);
285286
const data = await res.json();
286287
setAuth(data);
287288
} catch (e) {
@@ -295,25 +296,25 @@ export default function App() {
295296

296297
const handleLogout = async () => {
297298
try {
298-
await fetch("/sqlite/auth/logout", { method: "POST" });
299+
await fetch(`${AUTH}/logout`, { method: "POST" });
299300
setAuth({ ...auth, authenticated: false, user: null });
300301
notifications.show({
301-
title: "Logged out",
302-
message: "You have been successfully logged out",
303-
color: "gray"
302+
title: "Logged out",
303+
message: "You have been successfully logged out",
304+
color: "gray",
304305
});
305306
} catch (e) {
306307
notifications.show({
307-
title: "Error",
308-
message: "Failed to logout",
309-
color: "red"
308+
title: "Error",
309+
message: "Failed to logout",
310+
color: "red",
310311
});
311312
}
312313
};
313-
314+
314315
// State
315316
const [tables, setTables] = useState([]);
316-
// ... (rest of App state)
317+
// ... (rest of App state)
317318

318319
const [currentTable, setCurrentTable] = useState(null);
319320
const [columns, setColumns] = useState([]);
@@ -1075,7 +1076,7 @@ export default function App() {
10751076

10761077
<Divider my="sm" color="#E8E5E0" />
10771078

1078-
<TableSelector
1079+
<TableSelector
10791080
tables={tables}
10801081
favorites={favorites}
10811082
currentTable={currentTable}
@@ -1140,22 +1141,41 @@ export default function App() {
11401141
<Switch
11411142
checked={dark}
11421143
size="sm"
1143-
onLabel={<IconMoon size={12} stroke={2.5} color="var(--mantine-color-yellow-4)" />}
1144-
offLabel={<IconSun size={12} stroke={2.5} color="var(--mantine-color-gray-6)" />}
1144+
onLabel={
1145+
<IconMoon
1146+
size={12}
1147+
stroke={2.5}
1148+
color="var(--mantine-color-yellow-4)"
1149+
/>
1150+
}
1151+
offLabel={
1152+
<IconSun
1153+
size={12}
1154+
stroke={2.5}
1155+
color="var(--mantine-color-gray-6)"
1156+
/>
1157+
}
11451158
readOnly
11461159
style={{ pointerEvents: "none" }}
11471160
/>
11481161
}
11491162
>
11501163
Dark Mode
11511164
</Menu.Item>
1152-
<Menu.Item leftSection={<IconSettings size={14} />} onClick={openSecurity}>
1165+
<Menu.Item
1166+
leftSection={<IconSettings size={14} />}
1167+
onClick={openSecurity}
1168+
>
11531169
Settings
11541170
</Menu.Item>
11551171

11561172
<Menu.Divider />
11571173

1158-
<Menu.Item color="red" leftSection={<IconLogout size={14} />} onClick={handleLogout}>
1174+
<Menu.Item
1175+
color="red"
1176+
leftSection={<IconLogout size={14} />}
1177+
onClick={handleLogout}
1178+
>
11591179
Logout
11601180
</Menu.Item>
11611181
</Menu.Dropdown>
@@ -1165,10 +1185,8 @@ export default function App() {
11651185
<AppShell.Main>
11661186
<SecuritySettings opened={securityOpened} onClose={closeSecurity} />
11671187
{sqlMode ? (
1188+
// ... (rest of AppShell content)
11681189

1169-
// ... (rest of AppShell content)
1170-
1171-
11721190
// SQL MODE LAYOUT
11731191
<Box p="xl" style={{ maxWidth: 900, margin: "0 auto" }}>
11741192
<Group mb="xl" gap="sm">
@@ -1757,7 +1775,9 @@ export default function App() {
17571775
}}
17581776
onSelectAll={(checked) => {
17591777
if (checked) {
1760-
setSelectedRows(new Set(rows.map((r) => String(r[pk]))));
1778+
setSelectedRows(
1779+
new Set(rows.map((r) => String(r[pk])))
1780+
);
17611781
} else {
17621782
setSelectedRows(new Set());
17631783
}
@@ -1775,7 +1795,9 @@ export default function App() {
17751795
getColumnIcon={getColumnIcon}
17761796
onDeleteRecord={deleteRecord}
17771797
editingCell={editingCell}
1778-
onStartEdit={(rowPk, column) => setEditingCell({ rowPk, column })}
1798+
onStartEdit={(rowPk, column) =>
1799+
setEditingCell({ rowPk, column })
1800+
}
17791801
onUpdateCell={updateCell}
17801802
onCancelEdit={() => setEditingCell(null)}
17811803
fkMap={fkMap}
@@ -1784,7 +1806,7 @@ export default function App() {
17841806
getTagColor={getTagColor}
17851807
isTagColumn={isTagColumn}
17861808
/>
1787-
1809+
17881810
<Pagination
17891811
page={page}
17901812
total={total}

0 commit comments

Comments
 (0)