AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Wie / Womit werden Webanwendungen designt ?
Thema durchsuchen
Ansicht
Themen-Optionen

Wie / Womit werden Webanwendungen designt ?

Ein Thema von v2afrank · begonnen am 13. Jan 2014 · letzter Beitrag vom 31. Jan 2014
 
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.372 Beiträge
 
Delphi 12 Athens
 
#15

AW: Wie / Womit werden Webanwendungen designt ?

  Alt 14. Jan 2014, 15:16
Von Codegear/Emba gibt es auch "Delphi for PHP" bzw. RadPHP und HTML5 Builder.



Ganz "billig" geht auch TidHTTPServer.

HTML-Datei ausgeben und dann entsprechend die GET/POST-Daten auswerten.



z.B.: Ein billiger File-Server, welcher eine HTML-Webseite und Zusatzdateien ausliefert.

Das hatte ich mir implementiert:
- OnCommandGet (GET)
- OnException
- OnListenException

geht auch:
- OnCommandOther (POST?)
- und dazu dann noch eine Authentifizierungs- und Session-Behandlung (für ein Login der Benutzer)


So wie bei HTMLPath = 'info' kann man auf bestimmte URLs aka "Befehle" reagieren und dort entsprechende Webseiten ausliefern.
Und ansonsten werden die Dateien in einem bestimmten Verzeichnis (Path_Help) ausgeliefert. (Bilder, CSS, JS, hartcodierte HTML-Seiten usw.)
In die HTML-Dateien kommen dann noch ein paar Formulare, welche z.B. via POST ihre Daten übertragen (an einen entsprechende URL/Befehl)
Das HTML kann im Programm dynamisch zusammengesetzt werden, wofür es auch entsprechende Frameworks gibt, oder es kommt aus externen Dateien/Resourcen und da werden per StringReplace eventuell noch ein paar Platzhalter aufgefüllt.

Delphi-Quellcode:
procedure TMyService.HTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
const
  // http://de.selfhtml.org/diverses/mimetypen.htm
  FileExt: array[0..7] of string = ('', '.txt', '.html', '.css', '.js', '.gif', '.jpeg', '.png');
  ContentType: array[0..7] of string = ('application/octet-stream', 'text/plain', 'text/html', 'text/css', 'text/js', 'image/gif', 'image/jpeg', 'image/png');
var
  HTMLPath: string;
begin
  try
    HTMLPath := ARequestInfo.Document;
    while (HTMLPath <> '') and CharInSet(HTMLPath[1], ['/', '\', '.', ':']) do
      Delete(HTMLPath, 1, 1);
    if HTMLPath = 'infothen begin
      LogEvent('WebServer-Get 200: ' + ARequestInfo.URI + ' => ' + ARequestInfo.From);
      AResponseInfo.ContentType := 'text/plain';
      AResponseInfo.ResponseNo := 200;
      AResponseInfo.ResponseText := 'OK';
      AResponseInfo.ContentText := 'ServiceName: ' + DataServer1.ServiceName + #10
                                  + 'ServicePath: ' + ParamStr(0) + #10
                                  + 'ServerName: ' + TDSServerMethods(nil).ServerComputerName + #10 // geht, da ServerComputerName auf nichts einer TDSServerMethods-Instanz zugreift
                                  + #10
                                  + 'HelpName: ' + HTTPServer1.ServerSoftware + #10
                                  + 'HelpPort: ' + IntToStr(HTTPServer1.DefaultPort) + #10
                                  + 'HelpPath: ' + Path_Help + #10;
    end else if (Trim(HTMLPath) = '') or (TPath.GetExtendedPrefix(HTMLPath) <> TPathPrefixType.pptNoPrefix) or not TPath.HasValidFileNameChars(HTMLPath, False) then begin
      LogEvent('WebServer-Get 403: ' + ARequestInfo.URI + ' => ' + ARequestInfo.From);
      AResponseInfo.ContentType := 'text/plain';
      AResponseInfo.ResponseNo := 403;
      AResponseInfo.ResponseText := 'Forbidden';
      AResponseInfo.ContentText := '403 Forbidden'#10#10 + HTMLPath;
    end else if not FileExists(Path_Help + HTMLPath) then begin
      LogEvent('WebServer-Get 404: ' + ARequestInfo.URI + ' => ' + ARequestInfo.From);
      AResponseInfo.ContentType := 'text/plain';
      AResponseInfo.ResponseNo := 404;
      AResponseInfo.ResponseText := 'Not Found';
      AResponseInfo.ContentText := '404 Not Found'#10#10 + HTMLPath;
    end else begin
      LogEvent('WebServer-Get: ' + ARequestInfo.URI + ' => ' + ARequestInfo.From);
      AResponseInfo.ContentType := ContentType[Max(IndexText(ExtractFileExt(HTMLPath), FileExt), 0)];
      AResponseInfo.ResponseNo := 200;
      AResponseInfo.ResponseText := 'OK';
      AResponseInfo.ContentStream := TFileStream.Create(Path_Help + HTMLPath, fmOpenRead or fmShareDenyWrite); // Daten
      AResponseInfo.ContentLength := AResponseInfo.ContentStream.Size; // Datenmenge
      AResponseInfo.CacheControl := 'public'; // Browsercache verwenden
      AResponseInfo.Date := TFile.GetLastWriteTime(Path_Help + HTMLPath); // Änderungsdatum
      AResponseInfo.ETag := Format('%d_%.5f', [AResponseInfo.ContentLength, AResponseInfo.Date]); // (billiger) Hash
    end;
  except
    on E: Exception do begin
      LogEvent('WebServer-Get-Error: ' + ARequestInfo.URI + ' => ' + ARequestInfo.From + sLineBreak + E.ClassName + ': ' + E.Message);
      AResponseInfo.ContentType := 'text/plain';
      AResponseInfo.ResponseNo := 500;
      AResponseInfo.ResponseText := 'Internal Error';
      AResponseInfo.ContentStream.Free;
      AResponseInfo.ContentStream := nil;
      AResponseInfo.ContentLength := 0;
      AResponseInfo.ContentText := '500 Internal Error'#10#10 + E.ClassName + ': ' + E.Message + #10#10 + HTMLPath;
      AResponseInfo.CacheControl := '';
      AResponseInfo.Date := 0;
      AResponseInfo.ETag := '';
    end;
  end;
end;
Ein Therapeut entspricht 1024 Gigapeut.

Geändert von himitsu (14. Jan 2014 um 15:19 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:57 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz