npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nosdav-server

v0.0.53

Published

nosdav server

Downloads

384

Readme



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

  ✓  HTTP(S) server
  ✓  PUT and GET requests for uploading and downloading files
  ✓  Nostr event validation using nostr-tools and NIP-98
  ✓  CORS handling
  ✓  Basic file validation
  ✓  Proper response headers

Requirements

  • Node.js v12 or higher

Installation

Clone the repository and install:

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

Setup

To use this server using, 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 --key private-key.pem --cert fullchain.pem --port your_port

Options

-p or --port: The port on which the server should listen. Default: 3118
-r or --root: The root directory for file storage. Default: 'data'
-s or --https: A flag to enable HTTPS. Default: true (HTTPS)
-m or --mode: singleuser or multiuser. Default: multiuser
-k or --key: The path to the private key file. Default: './privkey.pem' (optional)
-c or --cert: The path to the certificate file. Default: './fullchain.pem' (optional)
-o or --owners: pubkeys (csv) of owners in singleuser mode (optional)

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

In multiuser mode the pubkey will be used to create per user directories beneath the root directory.

JavaScript Library

import http from 'http';
import { createRequestHandler } from 'nostr-server-library';

const port = 3000;
const rootDir = './data'; // The root directory where all files will be stored
const mode = 'singleuser'; // The server mode: 'singleuser' or 'multiuser'
const owners = ['public_key1','public_key2']; // array of public keys

const requestHandler = createRequestHandler(rootDir, mode, owners);

const server = http.createServer(requestHandler);

server.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

API Endpoints

PUT /:nostrid/:filename

Upload a file for the given Nostr.

Header: Authorization: Nostr base64(NostrEvent)

{
  "kind": 27235,
  "created_at": "Math.floor(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.

Where nostrid is the pubkey of the user, but only in multiuser mode

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