1.2.0 • Published 1 year ago

@async3619/haunted v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

📖 About

Haunted is music metadata retrieving server. this server retrieves metadata from several sources and serves it to client.

This server is mainly used for Cruise. but you can use it for everything you want.

🚀 Getting Started

📦 Using Docker

docker run -d -p 3000:3000 async3619/haunted:latest

📦 Using Docker Compose

version: "3.7"

services:
    haunted:
        image: async3619/haunted:latest
        ports:
            - "3000:3000"
        volumes:
            - ./config.json:/home/node/config.json:ro

📝 Usage

Before using this server in client side, you need to launch this server. see Getting Started section.

📡 TRPC

you can use this server with TRPC. we provide a type-safe client for TRPC. we also provide server-side router types for client usage. all you need to do is to import Router type from @async3619/haunted.

now, you should install @async3619/haunted package in your client project to get type definitions.

npm install @async3619/haunted 

# or

yarn add @async3619/haunted

# or

pnpm add @async3619/haunted

now you can use this server with TRPC:

import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
import { Router } from "@async3619/haunted";
//       ^^^^^^ this will make you comfy and type-safe with your IDE

// ...

const client = createTRPCProxyClient<Router>({
    links: [httpBatchLink({ url: "http://localhost:3000/trpc" })],
});

const result = await client.searchAlbums({ query: "독립음악", limit: 5, locale: "ko_KR" });
console.log(result); // [{ ... }]

📡 GraphQL

In addition to TRPC, you can use this server with GraphQL. we provide schema definitions for GraphQL. you can use ./schema.graphql file to generate your client-side code with your favorite GraphQL client generator such as apollo-codegen or graphql-codegen.

import { ApolloClient, InMemoryCache, gql } from "@apollo/client"; // or your favorite GraphQL client

const client = new ApolloClient({
    uri: "http://localhost:3000/graphql",
    cache: new InMemoryCache(),
});

const result = await client.query({
    query: gql`
        query SearchAlbums($input: SearchInput!) {
            searchAlbums(input: $input) {
                title
                artists
            }
        }
    `,
    variables: {
        query: "독립음악",
    },
});

console.log(result.data); // { searchAlbums: [{ ... }] }

🛠️ Configuration

This server uses config.json file from current working directory. we provide the configuration schema in config.schema.json file. you can use this file to validate your configuration file in your IDE.

{
    servers: {
        trpc: {
            path: "/trpc",
        },
        graphql: {
            path: "/graphql",
        },
    },
    cacheTTL: 3600, // cache TTL in seconds
    resolvers: {
        // whatever resolvers you want to use
        spotify: {
            clientId: "<your spotify client id>",
            clientSecret: "<your spotify client secret>",
        },
    },
}

🎵 Resolvers

Currently, this server supports Spotify resolver only. but we are planning to add more resolvers in the future.

Supported Resolvers

ServiceSupport?
Spotify
YouTube Music
Apple Music
Deezer
1.2.0

1 year ago

1.1.1

1 year ago