2017-05-26 02:57:09 -05:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-06-08 08:40:51 -05:00
|
|
|
"flag"
|
2017-05-26 02:57:09 -05:00
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
2017-08-03 09:10:39 -05:00
|
|
|
"github.com/gorilla/mux"
|
2017-05-26 02:57:09 -05:00
|
|
|
"github.com/matrix-org/dendrite/common"
|
2017-06-19 09:21:04 -05:00
|
|
|
"github.com/matrix-org/dendrite/common/config"
|
2017-05-26 02:57:09 -05:00
|
|
|
"github.com/matrix-org/dendrite/mediaapi/routing"
|
2017-05-26 09:49:54 -05:00
|
|
|
"github.com/matrix-org/dendrite/mediaapi/storage"
|
2017-05-26 02:57:09 -05:00
|
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
logDir = os.Getenv("LOG_DIR")
|
2017-07-28 05:32:17 -05:00
|
|
|
configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
|
2017-05-26 02:57:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
common.SetupLogging(logDir)
|
|
|
|
|
2017-06-08 08:40:51 -05:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *configPath == "" {
|
|
|
|
log.Fatal("--config must be supplied")
|
|
|
|
}
|
2017-06-19 09:21:04 -05:00
|
|
|
cfg, err := config.Load(*configPath)
|
2017-05-26 02:57:09 -05:00
|
|
|
if err != nil {
|
2017-06-19 09:21:04 -05:00
|
|
|
log.Fatalf("Invalid config file: %s", err)
|
2017-05-26 02:57:09 -05:00
|
|
|
}
|
2017-06-06 18:12:49 -05:00
|
|
|
|
2017-06-19 09:21:04 -05:00
|
|
|
db, err := storage.Open(string(cfg.Database.MediaAPI))
|
2017-05-26 02:57:09 -05:00
|
|
|
if err != nil {
|
2017-06-19 09:21:04 -05:00
|
|
|
log.WithError(err).Panic("Failed to open database")
|
2017-06-06 18:12:49 -05:00
|
|
|
}
|
|
|
|
|
2017-06-19 09:21:04 -05:00
|
|
|
log.Info("Starting media API server on ", cfg.Listen.MediaAPI)
|
2017-06-06 18:12:49 -05:00
|
|
|
|
2017-08-03 09:10:39 -05:00
|
|
|
api := mux.NewRouter()
|
2017-09-07 06:50:39 -05:00
|
|
|
routing.Setup(api, cfg, db)
|
2017-08-03 09:10:39 -05:00
|
|
|
common.SetupHTTPAPI(http.DefaultServeMux, api)
|
|
|
|
|
2017-06-19 09:21:04 -05:00
|
|
|
log.Fatal(http.ListenAndServe(string(cfg.Listen.MediaAPI), nil))
|
2017-05-26 02:57:09 -05:00
|
|
|
}
|