New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket host and the restful host setup #1069

jjhesk opened this Issue Aug 20, 2018 · 0 comments


None yet
1 participant

jjhesk commented Aug 20, 2018

I have been trying setup both hosts for websocket and the restful http host. Are there such example for more references?

i used the websocket code and it is not working...

Error during WebSocket handshake: Unexpected response code: 200

func StartWebsocket(app *iris.Application) {
	ws := websocket.New(websocket.Config{
		ReadBufferSize:    1024,
		WriteBufferSize:   1024,
		EnableCompression: true,
	app.Get("/ws", ws.Handler())
	app.Any("/iris-ws.js", func(ctx iris.Context) {


func SetupWebClient() {
	app := iris.New()
	app.RegisterView(iris.HTML("./dist", ".html").Reload(false))
	app.OnErrorCode(iris.StatusInternalServerError, func(ctx iris.Context) {
		// .Values are used to communicate between handlers, middleware.
		errMessage := ctx.Values().GetString("error")
		if errMessage != "" {
			ctx.Writef("Internal server error: %s", errMessage)
		ctx.Writef("(Unexpected) internal server error")

	app.Use(func(ctx iris.Context) {
		ctx.Application().Logger().Infof("Begin request for path: %s", ctx.Path())

	app.Get("/", routeHome)

	app.Get("/encode", func(ctx iris.Context) {
		doe := User{
			Username:  "Johndoe",
			Firstname: "John",
			Lastname:  "Doe",
			City:      "Neither FBI knows!!!",
			Age:       25,


	apiRoute := app.Party("api.", logThisMiddleware)
		// Method GET: http://localhost:8080/users/42
		apiRoute.Get("/users/{id:int min(1)}", getUserByID)
		// Method POST: http://localhost:8080/users/create
		apiRoute.Post("/users/create", createUser)
		apiRoute.Any("/iris-ws.js", websocket.ClientHandler())
		app.Post("/decode", func(ctx iris.Context) {
			var user User
			ctx.Writef("%s %s is %d years old and comes from %s", user.Firstname, user.Lastname, user.Age, user.City)
	assetHandler := app.StaticHandler("./dist", false, false)

	go StartWebsocket(app)
	// Listen for incoming HTTP/1.x & HTTP/2 clients on localhost port 8080.
	app.Run(iris.Addr(":8001"), iris.WithCharset("UTF-8"), iris.WithoutVersionChecker)

	//go statics.Run(iris.Addr(":8002"))


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment