2022-02-23 16:50:03 +00:00
|
|
|
# @padloc/server
|
|
|
|
|
|
|
|
This package contains the Padloc backend server component.
|
|
|
|
|
|
|
|
## How to use
|
|
|
|
|
2022-04-12 14:26:52 +00:00
|
|
|
### Through Docker
|
|
|
|
|
|
|
|
The recommended setup for hosting the Padloc server is through Docker (For v4,
|
|
|
|
you'll have to build the Docker image from source for now. Official image coming
|
|
|
|
soon!):
|
|
|
|
|
|
|
|
```sh
|
|
|
|
docker build -t padloc/server github.com/padloc/padloc#v4 -f Dockerfile-server
|
|
|
|
docker run padloc/server
|
|
|
|
```
|
|
|
|
|
|
|
|
For some examples of a Docker-based setup, check out our
|
2022-04-12 14:34:00 +00:00
|
|
|
[Docker Examples](../../docs/examples/hosting/docker).
|
2022-04-12 14:26:52 +00:00
|
|
|
|
|
|
|
### Directly through Node.js
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
Currently the `@padloc/server` package is meant to be run from within the
|
|
|
|
[Padloc monorepo](../../README.md). A standalone npm package is coming soon!
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
First, clone and install the monorepo:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
git clone git@github.com:padloc/padloc.git
|
|
|
|
cd padloc
|
|
|
|
npm ci
|
|
|
|
```
|
|
|
|
|
|
|
|
Then, you can either start the server from the root of the project...
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm run server:start
|
|
|
|
```
|
|
|
|
|
|
|
|
Or from the package directory.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
cd packages/server
|
|
|
|
npm start
|
|
|
|
```
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
By default, the server will listen on port `3000`. To can set a different port
|
|
|
|
via the `PL_TRANSPORT_HTTP_PORT` environment variable:
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
PL_TRANSPORT_HTTP_PORT=3001 npm start
|
|
|
|
```
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
For more configuration options, please consult the
|
|
|
|
[Configuration](#configuration) section of this readme.
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
Padloc comes with a lot of configuration options, most of which deal with
|
|
|
|
selecting and configuring backends for certain aspects of the software.
|
|
|
|
|
|
|
|
All configuration options for the `@padloc/server` package are defined in the
|
|
|
|
[src/config](src/config.ts) moule, and while we'll be discussing the most
|
|
|
|
important ones here, looking at the source can be a great way to understand how
|
|
|
|
configuration options are structured and parsed, and to familiarise yourself
|
|
|
|
with some of the more advanced configuration options.
|
|
|
|
|
|
|
|
Most of Padloc's configuration happens through environment variables, and
|
|
|
|
because there are a lot of options and therefore a lot of different variables,
|
|
|
|
we've come up with a simple naming scheme that's based on the hierarchical
|
|
|
|
nature of Padloc's configuration. This means that most of the time, you'll be
|
|
|
|
able to guess the environment variable name simply by looking at the structure
|
|
|
|
defined in [src/config](src/config.ts).
|
|
|
|
|
|
|
|
The generall pattern is that in order to configure a certain aspect, you'll
|
|
|
|
first choose which backend you want to use. Then, you'll provide the
|
|
|
|
configuration options required by that specific backend by setting the
|
|
|
|
corresponding environment variables, which are name-spaced with the backend's
|
|
|
|
name.
|
|
|
|
|
|
|
|
For example, you can choose which backend to use for data storage by setting the
|
|
|
|
`PL_DATA_BACKEND` variable. By default, Padloc uses LevelDB for data storage on
|
|
|
|
the server side. To use PostgreSQL instead, simply set the `PL_DATA_BACKEND`
|
2022-02-23 16:50:03 +00:00
|
|
|
variable to `postgres`.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
PL_DATA_BACKEND=postgres
|
|
|
|
```
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
Naturally, Padloc now needs to know where to reach the Postgres server, so
|
|
|
|
you'll need to set the corresponding environment variables. Our naming scheme
|
|
|
|
dictates that all postgres-related configuration options are prefixed with
|
|
|
|
`PL_DATA_POSTGRES_*`. An exampe for a full postgres configuration might look as
|
|
|
|
follows:
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
PL_DATA_BACKEND=postgres
|
|
|
|
PL_DATA_POSTGRES_HOST=localhost
|
|
|
|
PL_DATA_POSTGRES_PORT=5432
|
|
|
|
PL_DATA_POSTGRES_USER=someuser
|
|
|
|
PL_DATA_POSTGRES_PASSWORD=somepassword
|
|
|
|
PL_DATA_POSTGRES_DATABASE=padloc
|
|
|
|
```
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
Padloc is designed to be extremely modular, so you'll find that most aspects of
|
|
|
|
the software can be configured to use different backends. And if your technology
|
|
|
|
of choice isn't supported, it's usually fairly straightforward to implement the
|
|
|
|
required backend. [Pull requests welcome](../../README.md#contributing)!
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
### Setting Environment Variables
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
Environment variables can be set either the traditional way (consult the
|
|
|
|
documentation of your operating system) or via a
|
|
|
|
[`.env`](https://www.npmjs.com/package/dotenv) file. By default, Padloc will
|
|
|
|
look for a file named `.env` in the current working directory, but you can also
|
|
|
|
specifiy the path to a different file using the `--env` flag:
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
npm start -- --env=/path/to/env/file/.env
|
|
|
|
```
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
Note that by default, environment variables set through other means take
|
|
|
|
preference over the ones defined in your `.env` file. If you want your `.env`
|
|
|
|
file to override any variables set elsewhere, use the `--env-override` flag:
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
npm start -- --env=/path/to/env/file/.env --env-override
|
|
|
|
```
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
For your convenience, we've compiled **all** available environment variables in
|
|
|
|
a [`sample .env file`](resources/example.env). Simply copy the file to wherever
|
|
|
|
you want to keep it and the uncomment and edit any options you want to set (more
|
|
|
|
info about the most important configuration options below).
|
2022-02-23 16:50:03 +00:00
|
|
|
|
2022-02-25 14:10:06 +00:00
|
|
|
### General Server Options
|
|
|
|
|
|
|
|
TBD
|
|
|
|
|
2022-02-23 16:50:03 +00:00
|
|
|
### Data Transport
|
|
|
|
|
|
|
|
TBD
|
|
|
|
|
|
|
|
### Data Storage
|
|
|
|
|
|
|
|
TBD
|
|
|
|
|
|
|
|
### Attachment Storage
|
|
|
|
|
|
|
|
TBD
|
|
|
|
|
|
|
|
### Logging
|
|
|
|
|
|
|
|
TBD
|
|
|
|
|
|
|
|
### Authentication
|
|
|
|
|
|
|
|
TBD
|
|
|
|
|
|
|
|
### Provisioning
|
|
|
|
|
|
|
|
TBD
|
|
|
|
|
2022-02-25 14:10:06 +00:00
|
|
|
## Development
|
2022-02-23 16:50:03 +00:00
|
|
|
|
2022-02-25 14:10:06 +00:00
|
|
|
For development instructions, please refer to the
|
|
|
|
[monorepo readme](../../README.md#development).
|
|
|
|
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
For info on how to contribute to Padloc, please refer to the
|
|
|
|
[monorepo readme](../../README.md#contributing).
|
2022-02-23 16:50:03 +00:00
|
|
|
|
|
|
|
## Licensing
|
|
|
|
|
2022-02-24 09:06:06 +00:00
|
|
|
This software is published under the
|
|
|
|
[GNU Affero General Public License](../../LICENSE). If you wish to acquire a
|
2022-02-23 16:50:03 +00:00
|
|
|
commercial license, please contact us as
|
|
|
|
[sales@padloc.app](mailto:sales@padloc.app?subject=Padloc%20Commercial%20License).
|