Naveen
Naveen

Reputation: 777

How to load angular build files in Go

I have a dist folder in my Go project. That contain angular build files.

import (
    "github.com/gin-contrib/cors"
    "github.com/gin-gonic/contrib/static"
    "github.com/gin-gonic/gin"
)
func SetRoutes() *gin.Engine {
    router := gin.Default()
    router.Use(cors.Default())
    router.Use(static.Serve("/", static.LocalFile("./client/dist", true)))
    router.Run(":8080")
}

Using above code I can serve dist folder files. But if I refresh browser, it will not get those files. Shows error "404 page not found".

Upvotes: 0

Views: 922

Answers (2)

startsWith_R
startsWith_R

Reputation: 131

adding to @Dulquer answer make sure 'dist' folder contains 'index.html' file as direct child because 'ng build' creates a folder with the 'your-project-name' containing 'index.html' and places in 'dist' folder.

Upvotes: 0

Saiju
Saiju

Reputation: 350

router.Static("/", "./client/dist")

try this code. It should works.

Upvotes: 1

Related Questions