JSPM

  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q92012F
  • License MIT

nosdav server

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nosdav-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    nosdav-server

    nosdav-server

    Documentation


    GitHub license npm npm Github Stars

    Introduction

    NosDAV Server is a simple and secure file server implemented using Node.js, allowing clients to store and retrieve files over HTTPS. The server validates Nostr events in the authorization header and ensures that only authorized users can store and access files.

    Features

      ✓  HTTPS server
      ✓  PUT and GET requests for uploading and downloading files
      ✓  Nostr event validation using nostr-tools
      ✓  CORS handling
      ✓  Basic file validation
      ✓  Proper response headers

    Requirements

    • Node.js v12 or higher
    • HTTPS certificate and private key

    Installation

    Clone the repository and install:

    git clone https://github.com/nosdav/server.git && cd server
    npm install

    Setup

    To use this server, you need a valid private key (privkey.pem) and a certificate (fullchain.pem) for HTTPS. Place these files in the project directory or update the file paths in the options object when creating the server. An example way to generate these is below.

    openssl req -outform PEM -keyform PEM -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout ../privkey.pem -days 365 -out ../fullchain.pem

    Usage

    Start the server:

    node server.js private-key.pem fullchain.pem node [<your-port>]

    The server will listen for incoming requests at https://localhost:3118 if port is not set

    API Endpoints

    PUT /:nostrid/:filename

    Upload a file for the given Nostr.

    Header: Authorization: Nostr base64(NostrEvent)

    {
      "kind": 27235,
      "created_at": "Math.floor(http://Date.now() / 1000)",
      "tags": [["u", "path"]],
      "content": ""
    }

    Signed with the pubkey of the user.

    Content-Type can vary according to the file being uploaded.

    GET /:nostrid/:filename

    Download a file by its name for a specific Nostr.

    Docker

    Building the Docker Image

    First, you need to build the Docker image for the server. Navigate to the root directory of the project, where the Dockerfile is located, and run the following command:

    docker build -t nosdav .

    Running the Server with Docker

    Now that you have built the Docker image, you can run a container using that image. You can map the port and mount a volume to persist the data directory.

    Mapping the Port

    Use the -p flag to map the host port to the container port. In this case, we'll map the host port 3118 to the container port 3118:

    docker run -d -p 3118:3118 nosdav

    Mounting a Volume for Data Storage

    To persist the data directory across container restarts or removals, you can use the --mount flag to create a volume and mount it to the container:

    docker run -d -p 3118:3118 --mount type=bind,source=my-data,destination=/usr/src/app/data nosdav

    Replace my-data with your preferred volume name.

    Now your server is up and running with Docker. You can access it on your host machine at http://localhost:3118.

    Contributing

    Feel free to create a pull request if you would like to contribute or suggest improvements to the project. Please follow the existing style and add comments for any changes you make.

    License

    • MIT