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