Welcome to ServerFire, a powerful and lightweight server library!
ServerFire is not yet entirely complete. There are still many things that need to be done, including adding middleware for things such as database management and admin controls to help you better keep track of your websites and servers. However, ServerFire is still currently a fully-functioning server library with zero dependencies!
The following code enables you to create a very basic setup for a server and the server in fact does nothing, but this is the shell of your server code.
// Import required components from ServerFireconst{Server, bodyparser, Router, route, generateMiddleware, tools}=require('serverfire');// Create router middlewareconstrouter=newRouter();constr=route(router);// Create serverconstserver=newServer();server.create();// Add CORS; ideal for API developmentserver.use(tools.cors);// Add bodyparser for parsing POST requestsserver.use(bodyparser);// Include router in serverserver.use(r);// Start serverserver.listen(3000);If you would like to use Socket.io or any other similar packages, you can also read the server object directly from server.server in this setup!
Using the same setup, you can also use direct request handlers as is seen with these examples:
// GET requestrouter.get('/test',(req,res)=>{// Sends textres.send('Testing, testing, 1, 2, 3');});// POST requestrouter.post('/postTest',(req,res)=>{// Sends JSONres.sendJSON(req.body);console.log(req.body);});You can also add in URL parameters as is seen in this example:
// GET request for file path format /<username>/profile/// The "$" denotes a URL parameterrouter.get('/$username/profile',(req,res)=>{res.send('Profile reached for '+req.urlParams.username);});In addition to direct paths, you can also add static paths where every file in a given directory will be sent to the server. For example:
router.static('/',__dirname+'/public');This will push everything in the public directory to the root directory.
More information will be provided in the official documentation, including how to create middleware and more!
Thank you for choosing ServerFire to start up your website!