X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ffoundation%2Fapi%2Fapiserver%2Fapp%2Finit.go;fp=src%2Ffoundation%2Fapi%2Fapiserver%2Fapp%2Finit.go;h=117dd4e66f96e8ab0859599bae80ff57450ee7b1;hb=754bbb90fbbc06ef896673b7346c3086d481dca6;hp=0000000000000000000000000000000000000000;hpb=6ebd8c9c9a1e8cc534b6428c12d0cf6f4bfd9e04;p=iec.git diff --git a/src/foundation/api/apiserver/app/init.go b/src/foundation/api/apiserver/app/init.go new file mode 100644 index 0000000..117dd4e --- /dev/null +++ b/src/foundation/api/apiserver/app/init.go @@ -0,0 +1,59 @@ +package app + +import ( + "github.com/revel/revel" +) + +var ( + // AppVersion revel app version (ldflags) + AppVersion string + + // BuildTime revel app build-time (ldflags) + BuildTime string +) + +func init() { + // Filters is the default set of global filters. + revel.Filters = []revel.Filter{ + revel.PanicFilter, // Recover from panics and display an error page instead. + revel.RouterFilter, // Use the routing table to select the right Action + revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. + revel.ParamsFilter, // Parse parameters into Controller.Params. + revel.SessionFilter, // Restore and write the session cookie. + revel.FlashFilter, // Restore and write the flash cookie. + revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. + revel.I18nFilter, // Resolve the requested language + HeaderFilter, // Add some security based headers + revel.InterceptorFilter, // Run interceptors around the action. + revel.CompressFilter, // Compress the result. + revel.BeforeAfterFilter, // Call the before and after filter functions + revel.ActionInvoker, // Invoke the action. + } + + // Register startup functions with OnAppStart + // revel.DevMode and revel.RunMode only work inside of OnAppStart. See Example Startup Script + // ( order dependent ) + // revel.OnAppStart(ExampleStartupScript) + // revel.OnAppStart(InitDB) + // revel.OnAppStart(FillCache) +} + +// HeaderFilter adds common security headers +// There is a full implementation of a CSRF filter in +// https://github.com/revel/modules/tree/master/csrf +var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) { + c.Response.Out.Header().Add("X-Frame-Options", "SAMEORIGIN") + c.Response.Out.Header().Add("X-XSS-Protection", "1; mode=block") + c.Response.Out.Header().Add("X-Content-Type-Options", "nosniff") + c.Response.Out.Header().Add("Referrer-Policy", "strict-origin-when-cross-origin") + + fc[0](c, fc[1:]) // Execute the next filter stage. +} + +//func ExampleStartupScript() { +// // revel.DevMod and revel.RunMode work here +// // Use this script to check for dev mode and set dev/prod startup scripts here! +// if revel.DevMode == true { +// // Dev mode +// } +//}