2018-07-20 12:13:52 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-31 06:14:33 +00:00
|
|
|
|
2018-09-06 12:47:32 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2019-05-03 16:57:28 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/context"
|
2019-05-01 12:54:11 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-07-20 12:13:52 +00:00
|
|
|
)
|
|
|
|
|
2018-11-06 18:02:03 +00:00
|
|
|
// Start the REST API server using the configuration provided
|
2019-05-03 16:57:28 +00:00
|
|
|
func Start(ctx *context.Context) {
|
|
|
|
if ctx.HttpServerMode() != "" {
|
|
|
|
gin.SetMode(ctx.HttpServerMode())
|
|
|
|
} else if ctx.Debug() == false {
|
2018-09-13 09:34:56 +00:00
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
}
|
|
|
|
|
2019-05-02 12:10:05 +00:00
|
|
|
app := gin.New()
|
|
|
|
app.Use(gin.Logger(), gin.Recovery())
|
2018-07-20 12:13:52 +00:00
|
|
|
|
2018-09-24 09:27:46 +00:00
|
|
|
// Set template directory
|
2019-05-03 16:57:28 +00:00
|
|
|
app.LoadHTMLGlob(ctx.HttpTemplatesPath() + "/*")
|
2018-09-24 09:27:46 +00:00
|
|
|
|
2019-05-03 16:57:28 +00:00
|
|
|
registerRoutes(app, ctx)
|
2018-07-20 12:13:52 +00:00
|
|
|
|
2019-05-03 16:57:28 +00:00
|
|
|
if err := app.Run(fmt.Sprintf("%s:%d", ctx.HttpServerHost(), ctx.HttpServerPort())); err != nil {
|
2019-05-01 12:54:11 +00:00
|
|
|
log.Error(err)
|
|
|
|
}
|
2018-09-27 06:59:53 +00:00
|
|
|
}
|