Sunday, May 16, 2021

(not) Auto Vapor Restart

 I was thinking it might be fun to have auto restart of Vapor, like you can do with NodeJS. But then I thought more about what happens when you need to change multiple files, and you make change after change, and it won't build & run until you've made all of the changes.

Anyway, if you add this to routes.swift:

app.delete("kill-switch") { (req: Request) -> Response in
    exit(0)
}

And you start the server like so:

$ while true ; do vapor run ; sleep 3 ; done

Then you can restart it using curl or Postman or (if you use app.get) your browser:

$ curl -s 'http://localhost:8081/kill-switch' -X DELETE

Wait, what about reloading the page when the server restarts? That should be doable, right?

No comments: