2017-12-14 04:56:23 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kataras/iris/_examples/tutorial/vuejs-todo-mvc/src/todo"
|
|
|
|
"github.com/kataras/iris/_examples/tutorial/vuejs-todo-mvc/src/web/controllers"
|
|
|
|
|
|
|
|
"github.com/kataras/iris"
|
|
|
|
"github.com/kataras/iris/sessions"
|
2017-12-23 16:07:39 +01:00
|
|
|
"github.com/kataras/iris/websocket"
|
2017-12-16 05:38:28 +01:00
|
|
|
|
|
|
|
"github.com/kataras/iris/mvc"
|
2017-12-14 04:56:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2017-12-23 16:07:39 +01:00
|
|
|
|
2017-12-14 04:56:23 +01:00
|
|
|
// serve our app in public, public folder
|
|
|
|
// contains the client-side vue.js application,
|
|
|
|
// no need for any server-side template here,
|
|
|
|
// actually if you're going to just use vue without any
|
|
|
|
// back-end services, you can just stop afer this line and start the server.
|
|
|
|
app.StaticWeb("/", "./public")
|
|
|
|
|
2017-12-24 00:22:44 +01:00
|
|
|
// configure the http sessions.
|
2017-12-14 04:56:23 +01:00
|
|
|
sess := sessions.New(sessions.Config{
|
2017-12-23 16:07:39 +01:00
|
|
|
Cookie: "iris_session",
|
2017-12-14 04:56:23 +01:00
|
|
|
})
|
|
|
|
|
2017-12-24 00:22:44 +01:00
|
|
|
// configure the websocket server.
|
2017-12-23 16:07:39 +01:00
|
|
|
ws := websocket.New(websocket.Config{})
|
2017-12-14 04:56:23 +01:00
|
|
|
|
2017-12-24 00:22:44 +01:00
|
|
|
// create a sub router and register the client-side library for the iris websockets,
|
|
|
|
// you could skip it but iris websockets supports socket.io-like API.
|
|
|
|
todosRouter := app.Party("/todos")
|
|
|
|
// http://localhost:8080/todos/iris-ws.js
|
|
|
|
// serve the javascript client library to communicate with
|
|
|
|
// the iris high level websocket event system.
|
|
|
|
todosRouter.Any("/iris-ws.js", websocket.ClientHandler())
|
|
|
|
|
2017-12-23 16:07:39 +01:00
|
|
|
// create our mvc application targeted to /todos relative sub path.
|
2017-12-24 00:22:44 +01:00
|
|
|
todosApp := mvc.New(todosRouter)
|
|
|
|
|
2017-12-16 05:38:28 +01:00
|
|
|
// any dependencies bindings here...
|
2017-12-27 03:15:41 +01:00
|
|
|
todosApp.Register(
|
2017-12-23 16:07:39 +01:00
|
|
|
todo.NewMemoryService(),
|
2017-12-25 19:57:04 +01:00
|
|
|
sess.Start,
|
2017-12-23 16:07:39 +01:00
|
|
|
ws.Upgrade,
|
2017-12-16 05:38:28 +01:00
|
|
|
)
|
2017-12-14 04:56:23 +01:00
|
|
|
|
|
|
|
// controllers registration here...
|
2017-12-27 03:15:41 +01:00
|
|
|
todosApp.Handle(new(controllers.TodoController))
|
2017-12-14 04:56:23 +01:00
|
|
|
|
|
|
|
// start the web server at http://localhost:8080
|
2017-12-23 16:07:39 +01:00
|
|
|
app.Run(iris.Addr(":8080"), iris.WithoutVersionChecker)
|
2017-12-14 04:56:23 +01:00
|
|
|
}
|