-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2ecef1
commit ab41f42
Showing
1 changed file
with
21 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
package handler | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"search/config" | ||
"search/routes" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/template/html/v2" | ||
) | ||
|
||
func main() { | ||
// Log the start of the application | ||
log.Println("Starting Fiber app...") | ||
func init() { | ||
// Initialize the database connection | ||
err := config.Database() | ||
if err != nil { | ||
log.Fatalf("Error initializing the database: %v", err) | ||
} | ||
} | ||
|
||
// Initialize the Fiber engine with templates | ||
func FiberHandler(c *fiber.Ctx) error { | ||
// Initialize the view engine for HTML templates | ||
engine := html.New("./views", ".html") | ||
|
||
// Create a new Fiber app | ||
// Create a new Fiber app with the views engine | ||
app := fiber.New(fiber.Config{ | ||
Views: engine, // Set the template engine | ||
Views: engine, | ||
}) | ||
|
||
// Serve static files | ||
// Serve static files from the public directory | ||
app.Static("/", "./public") | ||
|
||
// Define routes | ||
// Set up routes for your application | ||
routes.Routes(app) | ||
|
||
// Log the fact that we are listening on a port | ||
log.Println("App is listening on :3000") | ||
|
||
// Start the Fiber app (automatically listens and serves) | ||
if err := app.Listen(":3000"); err != nil { | ||
log.Fatal("Error starting server:", err) | ||
} | ||
// Return the server response to Vercel (using the handler) | ||
return app.Listen(":3000") | ||
} | ||
|
||
func init() { | ||
// Initialize the database before running the app | ||
log.Println("Initializing database...") | ||
config.Database() | ||
// This function is required for Vercel serverless deployment | ||
func Handler(c *fiber.Ctx) error { | ||
// Call the FiberHandler function to handle the request | ||
return FiberHandler(c) | ||
} | ||
|