Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

It doesn't work #32

@martinlasek

Description

@martinlasek

The Flash package doesn't seem to work.

Following the documentation, double checking the configuration and requirements. I even created a new project just to configure flash and have one route that does nothing but redirect to the next one whilst adding a flash message.

configure.swift

import Leaf
import Vapor
import Flash

/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
  /// Register providers first
  try services.register(LeafProvider())
  try services.register(FlashProvider())

  /// Register routes to the router
  let router = EngineRouter.default()
  try routes(router)
  services.register(router, as: Router.self)
    
  /// Use Leaf for rendering views
  config.prefer(LeafRenderer.self, for: ViewRenderer.self)

  /// Register middleware
  var middlewares = MiddlewareConfig() // Create _empty_ middleware config
  middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
  middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
  middlewares.use(SessionsMiddleware.self)
  middlewares.use(FlashMiddleware.self)
  services.register(middlewares)
}

routes.swift

import Vapor
import Flash

public func routes(_ router: Router) throws {
  router.get { req in
    return try req.view().render("welcome")
  }

  router.get("hello") { req -> Future<Response> in
    return req.future(req.redirect(to: "/").flash(.error, "Hey Listen!"))
  }
}

welcome.leaf

#set("title") { It works }

#set("body") {
  <div class="welcome">
    <div class="alerts">
      #flash() {
        #for(flash in all) {
          Message: #(flash.message)
          Type: #(flash.kind)
        }
      }
    </div>
    <img src="/images/it-works.png">
  </div>
}

#embed("base")

Putting a breakpoint in the package at the check whether flashes isEmpty shows, it is empty.. 🤔

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions