60 lines
1.3 KiB
Go
Raw Normal View History

2017-06-16 23:12:28 +00:00
package main
import (
2017-07-13 15:56:14 +00:00
"io/ioutil"
2017-06-16 23:12:28 +00:00
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components/js"
2017-06-16 23:12:28 +00:00
)
2017-10-02 00:09:05 +00:00
// configureAssets adds all the routes used for media assets.
func configureAssets(app *aero.Application) {
2017-10-01 22:31:44 +00:00
// Script bundle
scriptBundle := js.Bundle()
// Service worker
2017-07-13 15:56:14 +00:00
serviceWorkerBytes, err := ioutil.ReadFile("sw/service-worker.js")
serviceWorker := string(serviceWorkerBytes)
if err != nil {
panic("Couldn't load service worker")
}
2017-06-21 00:02:30 +00:00
app.Get("/scripts", func(ctx *aero.Context) string {
2017-10-01 22:31:44 +00:00
return ctx.JavaScript(scriptBundle)
2017-06-21 00:02:30 +00:00
})
2017-06-23 11:28:54 +00:00
app.Get("/scripts.js", func(ctx *aero.Context) string {
2017-10-01 22:31:44 +00:00
return ctx.JavaScript(scriptBundle)
2017-06-23 11:28:54 +00:00
})
2017-07-13 15:56:14 +00:00
app.Get("/service-worker", func(ctx *aero.Context) string {
2017-10-01 22:31:44 +00:00
return ctx.JavaScript(serviceWorker)
2017-07-13 15:56:14 +00:00
})
2017-06-18 11:50:53 +00:00
// Web manifest
app.Get("/manifest.json", func(ctx *aero.Context) string {
return ctx.JSON(app.Config.Manifest)
2017-06-16 23:12:28 +00:00
})
2017-06-18 11:50:53 +00:00
// Favicon
app.Get("/favicon.ico", func(ctx *aero.Context) string {
return ctx.TryWebP("images/brand/64", ".png")
})
2017-11-11 17:08:56 +00:00
// Images
app.Get("/images/*file", func(ctx *aero.Context) string {
return ctx.File("images" + ctx.Get("file"))
2017-06-16 23:12:28 +00:00
})
2017-11-13 17:07:25 +00:00
// Videos
app.Get("/videos/*file", func(ctx *aero.Context) string {
return ctx.File("videos" + ctx.Get("file"))
})
2017-06-16 23:12:28 +00:00
// For benchmarks
app.Get("/hello", func(ctx *aero.Context) string {
return ctx.Text("Hello World")
})
}