File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed
Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,18 @@ To use WebForms Core, first copy the WebForms class file in this directory to yo
55``` swift
66import Vapor
77
8+ struct FormData : Content {
9+ var txt_Name: String
10+ var txt_BackgroundColor: String
11+ var txt_FontSize: Int
12+ }
13+
814func routes (_ app : Application) throws {
915 app.post { req -> Response in
1016 guard let data = try ? req.content.decode (FormData.self ) else {
1117 throw Abort (.badRequest )
1218 }
13-
19+
1420 let name = data.txt_Name
1521 let backgroundColor = data.txt_BackgroundColor
1622 let fontSize = data.txt_FontSize
@@ -26,12 +32,10 @@ func routes(_ app: Application) throws {
2632
2733 return form.response ()
2834 }
29- }
3035
31- struct FormData : Content {
32- var txt_Name: String
33- var txt_BackgroundColor: String
34- var txt_FontSize: Int
36+ app.get { req in
37+ return Response (status : .ok , body : .init (string : renderForm ()))
38+ }
3539}
3640
3741func renderForm () -> String {
@@ -60,8 +64,20 @@ func renderForm() -> String {
6064 """
6165}
6266
63- app.get { req in
64- return Response (status : .ok , body : .init (string : renderForm ()))
67+ public func configure (_ app : Application) throws {
68+ // Register routes
69+ try routes (app)
70+ }
71+
72+ let app = Application ()
73+ defer { app.shutdown () }
74+
75+ do {
76+ try configure (app)
77+ try app.run ()
78+ } catch {
79+ app.logger .error (" Failed to start the app: \( error ) " )
80+ throw error
6581}
6682```
6783
You can’t perform that action at this time.
0 commit comments