Skip to content

Commit

Permalink
new waybgpt errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperninjaXII committed Nov 6, 2024
1 parent c2ecef1 commit ab41f42
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions api/index.go
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)
}

0 comments on commit ab41f42

Please sign in to comment.