Spaces:
Sleeping
Sleeping
File size: 3,218 Bytes
542878f a8ebadf 542878f a8ebadf 542878f a8ebadf a1eed6b d3c13b7 a8ebadf a1eed6b d3c13b7 a8ebadf f118f03 d3c13b7 542878f f118f03 a8ebadf f118f03 542878f a8ebadf a1eed6b a8ebadf 4597f89 a8ebadf 4597f89 a8ebadf a1eed6b 542878f a1eed6b 542878f a1eed6b 542878f f118f03 d3c13b7 a8ebadf 542878f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
package main
import (
"os"
"fmt"
"log"
"github.com/joho/godotenv"
// Fiber
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/helmet"
// Main Features
stock_proxy "tebakaja_lb_proxy/proxy/stock"
crypto_proxy "tebakaja_lb_proxy/proxy/crypto"
national_currency_proxy "tebakaja_lb_proxy/proxy/national_currency"
middlewares "tebakaja_lb_proxy/proxy/middlewares"
// Swagger
_ "tebakaja_lb_proxy/docs"
swagger "github.com/swaggo/fiber-swagger"
// Node Exporter
// exporter_proxy "tebakaja_lb_proxy/proxy/node_exporter"
)
// @title TebakAja
// @version 1.0
// @description TebakAja REST API Service
// @termsOfService https://swagger.io/terms/
// @contact.name Si Mimin
// @contact.url https://www.tebakaja.com
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host 192.168.137.1:7860
func main() {
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file")
}
proxyService := fiber.New()
proxyService.Use(helmet.New())
proxyService.Use(middlewares.LoggingMiddleware)
proxyService.Use(middlewares.RateLimiterMiddleware())
proxyService.Use(cors.New(cors.Config{
AllowOrigins: os.Getenv("TEBAKAJA_CORS_ALLOW_ORIGINS"),
AllowHeaders: os.Getenv("TEBAKAJA_CORS_ALLOW_HEADERS"),
AllowMethods: os.Getenv("TEBAKAJA_CORS_ALLOW_METHODS"),
AllowCredentials: true,
}))
proxyService.Use(func(c *fiber.Ctx) error {
c.Set("Content-Security-Policy", fmt.Sprintf("frame-ancestors 'self' %s %s %s %s %s %s",
"https://huggingface.co",
"https://qywok-tebakaja-proxy-space-0.hf.space",
"https://qywok-tebakaja-proxy-space-1.hf.space",
"https://qywok-tebakaja-proxy-space-2.hf.space",
"https://qywok-tebakaja-proxy-space-3.hf.space",
"https://qywok-tebakaja-proxy-space-4.hf.space",
))
return c.Next()
})
stockGroup := proxyService.Group("/stock")
stockGroup.Get("/lists",
stock_proxy.StockListsHandler(
&stock_proxy.StockServiceImpl{}))
stockGroup.Post("/prediction",
stock_proxy.StockPredictionHandler(
&stock_proxy.StockServiceImpl{}))
cryptoGroup := proxyService.Group("/crypto")
cryptoGroup.Get("/lists",
crypto_proxy.CryptoListsHandler(
&crypto_proxy.CryptoServiceImpl{}))
cryptoGroup.Post("/prediction",
crypto_proxy.CryptoPredictionHandler(
&crypto_proxy.CryptoServiceImpl{}))
nationalCurrencyGroup := proxyService.Group("/national-currency")
nationalCurrencyGroup.Get("/lists",
national_currency_proxy.NationalCurrencyListsHandler(
&national_currency_proxy.NationalCurrencyServiceImpl{}))
nationalCurrencyGroup.Post("/prediction",
national_currency_proxy.NationalCurrencyPredictionHandler(
&national_currency_proxy.NationalCurrencyServiceImpl{}))
proxyService.Get("/swagger/*", swagger.WrapHandler)
proxyService.Get("/", func(c *fiber.Ctx) error {
return c.Redirect("/swagger/index.html", fiber.StatusMovedPermanently)
})
HOST := os.Getenv("TEBAKAJA_PROXY_HOST")
PORT := os.Getenv("TEBAKAJA_PROXY_PORT")
log.Fatal(proxyService.Listen(fmt.Sprintf("%s:%s", HOST, PORT)))
}
|