Skip to content

Cppchamp/file-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

file-server

A simple file server made with python and flask

Running the file server

The easiest way to run the server is with docker. To run with docker, there is some configuration that has to be made. Create a .env file in the project root folder that holds the configuration for the server. This .env file is used to configure both the flask server and the file server. The parameters for the file server can be seen under backend/conf/files_config.py. The parameters are as follows:

Name Description Default Required
FILES_PATH The path that will be used to store files. When using docker, this should probably be set to /usr/userfiles, which is a path inside a named docker volume. /usr/files
(docker
only)
Yes
BANNED_EXTENSIONS Files with which extensions are forbidden from being uploaded to the server. Generally speaking, it's good to disallow .html and .js files.
The format of this variable is a comma separated list. E.g, html,js
- Yes
ADMINISTRATOR An administrator that will automatically be
inserted into the database when starting the server. The format of this variable is username:password
- No
FILES_SERVER_PROTOCOL The communication protocol that the file server uses. This affects the addresses for the API requests the frontend will send. http Yes
FILES_SERVER_ADDRESS The IP address that the frontend will refer to when making API requests to the file server. 127.0.0.1 Yes
FILES_SERVER_PORT The port that the file server will listen on. 5000 Yes
FILES_SERVER_THREADS How much threads the file server will use. 6 Yes
FILES_SQL_CONNECT_RETRY How many retries the file server will make to connect to the sql server before giving up. 50 Yes
FILES_SQL_CONNECT_RETRY_TIMER The time between attempts to connect to the sql server. 4sec Yes
FLASKENV_FROM_GLOBAL Whether the flask environment will be obtained by passing the entire environment (via iterating over all entries in os.getenv()) or only those specified in backend/flask_config.py
Note that it's generally better to add an entry to flask_config.py with the respective name rather then getting it from the entire environment as that could cause problems.
false Yes
MAKE_DIRS_OK Whether to create the folder specified by FILES_PATH in case it does not exist. false Yes
DEFAULTS_INFO Whether to log parameters using their default values. true Yes

Note that the FILES_PATH is inside a named docker volume serverfiles, when running with docker anyway.

On the docker topic, there is also some possible configuration there:

Name Description Default
REDIS_PORT The redis port mapping on the host 6379
MYSQL_PORT The mysql port mapping on the host 3306
HOST_FILES_SERVER_PORT The files server port mapping on the host 5000

Don't mix up the HOST_FILES_SERVER_PORT parameter and FILES_SERVER_PORT parameter. If running on docker, settings FILES_SERVER_PORT to something will set it inside the container, and setting HOST_FILES_SERVER_PORT will set the host mapping

The rest of the parameters are flask parameters, which can be viewed here. Also note that if not using FLASKENV_FROM_GLOBAL the configuration parameter may need to be specified under backend/flask_config.py (if it isn't already). It should be specified as:

<parameter_name> = getenv('<parameter_name_in_.env>')

E.g.: SECRET_KEY = getenv('SECRET_KEY')

With all that being said, a basic configuration file to get the server running might look like this:

#flask configuration
SECRET_KEY=FLASK_SECRET_KEY #This is an example key. DO NOT USE
SESSION_COOKIE_SAMESITE=None
SESSION_COOKIE_SECURE=True
MAX_CONTENT_LENGTH=10737418240
SESSION_PERMANENT=False
SESSION_USE_SIGNER=True
#file server configuration
ADMINISTRATOR=admin:admin #example value. DO NOT USE
#this can be ommited when running with docker as it's the default value.
#When running outside of docker though, this needs to be set manually.
FILES_PATH=/usr/userfiles
BANNED_EXTENSIONS=html,js
#mysql configuration
MYSQL_USER=mysqluser #example value. DO NOT USE
MYSQL_PASSWORD=mysqlpassword #example value. DO NOT USE
MYSQL_ROOT_PASSWORD=mysqlrootpassword #example value. DO NOT USE
MYSQL_DB=files

After all that pesky configuration is done, running docker compose up should fire up the server and it should be available at FILES_SERVER_PROTOCOL://FILES_SERVER_ADDRESS:FILES_SERVER_PORT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published