Skip to content

mtmr0x/rust-web-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Web Server Boilerplate

Start developing your Rust server based in this simple set up.

The following instructions are for MacOS or Linux.

If something doesn't work, open an issue or open a Pull Request following contribution guidelines;

Quick overview

# copy env sample file to .env file
cp ./.env.sample ./.env

# open it and replace its values
vim ./.env

Follow env files section for understanding it.

Then start the server using the start.sh script.

./start.sh # make sure you gave permissions to it

Table of contents

Installation

Install Rust

Go to https://www.rust-lang.org/tools/install and check installation methods

Note: this project is set with version 1.34.1 and tested with 1.29.0 and worked pretty well. You can define your version of Rust at your environment variables.

Set up

Environment variables

For properly run this project, you will have to set some environment variables. Everything you need to set up is located in .env.sample file.

Every update in your .env file you must add the new variable to the process at your start up script before running it. Open and edit the start.sh file present in the root directory of this project.

Run

Execute the start.sh script located in the this project:

./start.sh

Features

Logger

Logger configurations depends on LEVEL_VERBOSITY environment variable for deciding what levels of logs can be printed. LEVEL_VERBOSITY documentation and usage is present in .env.sample file.

stdout log:

The application logs stdout for instrumentation and its format is present in src/logger/logger.rs file, logging hour, target, level and message.

output file log:

The file output is set as output.log file, that will be present in the root directory as it has logs. It prints the same format of stdout logs with addition of Year, Month and Day of that output before the time of it.

Configuration

This application tries to follow configuration over convention. All types of configurations that is not Rust convention is placed as environment variable and all of them must be set, otherwise the application will fail to start.

You can find all necessary environment variables documented for this project inside .env.sample file.

Routing

This project is meant to be easy for people coming from NodeJS and that said the closest way to get there was to find a routing declaration library and framework that could make web development similar to ExpressJS or Koa. Iron and Router did the job.

To-do list

About

An implementation of a simple web server using Rust

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published