- Why should you restart an http server just for a small change in your source code. isn't HTTP meant to be stateless.
- Aren't you meant to have a static fetch-once properties for development.
If you agree with those philosophies, then you'll love HotPress.
What HotPress does is that it only initializes the server and required parameters once and pass it to your virtual server (Router).
npm install @soniccodes/hotpress
yarn add @soniccodes/hotpress
/**
@param server : Router
**/
function reload(server) {
server.get("/hi",function(req, res){
res.send("hi")
})
//Anything you'd do with a normal server.
}
modules.export = reload //This is very important
global.rootPatch = __dirname //Very important
const express = require("express")
const {setup,reload} = require("@soniccodes/hotpress")
const app = express()
setup({server:app,reloadable:"./foo.js"}) //Note: Relative path
app.listen(port,(err)=>{
if(err) throw err;
console.log("⚡ Ready on http://localhost:"+port);
})
global.rootPatch = __dirname //Very important
const express = require("express")
const app = express()
if(prod){
require("./foo.js")(app,...params)
}else{
const {setup,reload} = require("@soniccodes/hotpress")
setup({server:app,reloadable:"./foo.js"}) //Note: Relative path
}
app.listen(port,(err)=>{
if(err) throw err;
console.log("⚡ Ready on http://localhost:"+port);
})
Copyright 2021 Rami Mohammed
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.