Skip to content

Commit

Permalink
added new
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperninjaXII committed Nov 6, 2024
1 parent d240e25 commit a486f87
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.
38 changes: 38 additions & 0 deletions api/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// /api/index.go

package handler

import (
"net/http"
"search/config"
"search/routes"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
)

// Handler function expected by Vercel
func Handler(w http.ResponseWriter, r *http.Request) {
// Initialize the Fiber engine
engine := html.New("./../views", ".html")

// Create a new Fiber app
app := fiber.New(fiber.Config{
Views: engine, // Set the template engine
})

// Serve static files
app.Static("/", "./../public")

// Define routes
routes.Routes(app)

// Handle HTTP requests with Fiber
app.Listener = http.NewServeMux()
app.Listener.ServeHTTP(w, r)
}

func init() {
// Initialize the database before running the app
config.Database()
}
37 changes: 11 additions & 26 deletions app.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
package main

import (
"net/http"
"search/config"
"search/routes"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
)

// Exported function for Vercel
func HandleRequest(w http.ResponseWriter, r *http.Request) {
// Initialize the Fiber engine
engine := html.New("./views", ".html")

// Create a new Fiber app
app := fiber.New(fiber.Config{
Views: engine, // Set the template engine
})

// Serve static files
app.Static("/", "./public")

// Define routes
routes.Routes(app)

// Handle HTTP requests with Fiber
app.Listener = http.NewServeMux()
app.Listener.ServeHTTP(w, r)
}
import "search/config"

func init() {
// Initialize the database connection
config.Database()
}

func main() {
// main can remain empty or used for additional setup if necessary
}
engine := html.New("./views", ".html")
app := fiber.New(
fiber.Config{
Views: engine,
},
)
app.Static("/", "./public")
routes.Routes(app)

app.Listen(":3000")
}
2 changes: 1 addition & 1 deletion vercel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"builds": [
{
"src": "./app.go",
"src": "./api/index.go",
"use": "@vercel/go"
}
]
Expand Down

0 comments on commit a486f87

Please sign in to comment.