Major architecture update: stable identity, component validation, media indexing, and protocol docs
This commit is contained in:
1 parent
ce7c97d13a
commit
01c110bbe1
16 files changed
+2718
-468
No files matched your search
+41
-15
@@ -1,4 +1,5 @@
|
||||
import 'package:hotreloader/hotreloader.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:relic/relic.dart';
|
||||
|
||||
import 'config/config.dart';
|
||||
@@ -6,8 +7,10 @@ import 'src/auth/auth_middleware.dart';
|
||||
import 'src/gateway/gateway_handlers.dart';
|
||||
import 'src/handlers/auth_handlers.dart';
|
||||
import 'src/handlers/channel_handlers.dart';
|
||||
import 'src/handlers/dev_db_handlers.dart';
|
||||
import 'src/handlers/message_handlers.dart';
|
||||
import 'src/handlers/public_handlers.dart';
|
||||
import 'src/handlers/settings_handlers.dart';
|
||||
import 'src/handlers/upload_handlers.dart';
|
||||
import 'src/state/app_state.dart';
|
||||
|
||||
@@ -29,6 +32,10 @@ Future<void> startServer() async {
|
||||
..get('/.well-known/verify/:userId', publicVerifyHandler)
|
||||
..get('/.well-known/server', publicServerInfoHandler)
|
||||
..get('/uploads/:fileName', getUploadFileHandler)
|
||||
..get('/attachments/:attachmentId', getAttachmentHandler)
|
||||
..get('/avatars/:userId', getAvatarAliasHandler)
|
||||
..get('/icons/:serverId', getServerIconAliasHandler)
|
||||
..get('/banners/:serverId', getServerBannerAliasHandler)
|
||||
..get('/gateway', gatewayHandler)
|
||||
|
||||
// ============ PROTECTED ENDPOINTS (requires auth) ============
|
||||
@@ -36,6 +43,20 @@ Future<void> startServer() async {
|
||||
|
||||
// Current user
|
||||
..get('/api/me', getMeHandler)
|
||||
..patch('/api/me', updateProfileHandler)
|
||||
..put('/api/me/avatar', setAvatarHandler)
|
||||
|
||||
// Server settings
|
||||
..get('/api/server/settings', getServerSettingsHandler)
|
||||
..patch('/api/server/settings', patchServerSettingsHandler)
|
||||
..put('/api/server/icon', setServerIconHandler)
|
||||
..put('/api/server/banner', setServerBannerHandler)
|
||||
|
||||
// Dev DB tools (testing only, admin only, requires config flag)
|
||||
..get('/api/dev/db/snapshot', getDevDbSnapshotHandler)
|
||||
..post('/api/dev/db/reset', resetDevDbHandler)
|
||||
..post('/api/dev/users/promote-admin', promoteUserToAdminHandler)
|
||||
..post('/api/dev/users/demote-admin', demoteUserFromAdminHandler)
|
||||
|
||||
// Channels
|
||||
..get('/api/channels', getChannelsHandler)
|
||||
@@ -44,6 +65,9 @@ Future<void> startServer() async {
|
||||
|
||||
// Messages
|
||||
..get('/api/messages', getMessagesHandler)
|
||||
..get('/api/channels/:channelId/media', getChannelMediaHandler)
|
||||
..post('/api/uploads/init', initUploadHandler)
|
||||
..put('/api/uploads/:uploadId', completeUploadHandler)
|
||||
..post('/api/uploads', uploadFileHandler)
|
||||
..post('/api/messages', sendMessageHandler)
|
||||
..put('/api/messages/:messageId', editMessageHandler)
|
||||
@@ -54,26 +78,28 @@ Future<void> startServer() async {
|
||||
..fallback = respondWith((_) => Response.notFound());
|
||||
|
||||
print('');
|
||||
print('╔════════════════════════════════════════════╗');
|
||||
print('║ 🚀 Server starting... ║');
|
||||
print('║ Host: ${Config.serverHost.padRight(34)}║');
|
||||
print('║ URL: http://localhost:${Config.port.toString().padRight(26)}║');
|
||||
print('╚════════════════════════════════════════════╝');
|
||||
print('🚀 Server starting...');
|
||||
print('Bind: ${'${Config.bindHost}:${Config.bindPort}'.padRight(34)}');
|
||||
print('Public URL: ${Config.publicBaseUrl.padRight(26)}');
|
||||
print('');
|
||||
|
||||
await _currentApp!.serve(port: Config.port);
|
||||
final bindAddress = InternetAddress.tryParse(Config.bindHost) ?? (await InternetAddress.lookup(Config.bindHost)).first;
|
||||
|
||||
await _currentApp!.serve(
|
||||
address: bindAddress,
|
||||
port: Config.bindPort,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> stopServer() async {
|
||||
await _currentApp?.close();
|
||||
_currentApp = null;
|
||||
}
|
||||
|
||||
void main() async {
|
||||
initializeStore();
|
||||
Config.initialize();
|
||||
|
||||
// Enable hot reload in development
|
||||
await HotReloader.create(
|
||||
onAfterReload: (ctx) async {
|
||||
print('🔄 Changes detected! Restarting server...');
|
||||
await startServer();
|
||||
},
|
||||
);
|
||||
initializeStore();
|
||||
|
||||
await startServer();
|
||||
}
|
||||
Reference in new issue
Block a user