-
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
d240e25
commit a486f87
Showing
3 changed files
with
50 additions
and
27 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 |
---|---|---|
@@ -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() | ||
} |
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,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") | ||
} |
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,7 +1,7 @@ | ||
{ | ||
"builds": [ | ||
{ | ||
"src": "./app.go", | ||
"src": "./api/index.go", | ||
"use": "@vercel/go" | ||
} | ||
] | ||
|