BACKAN - Server
BACKAN Create endpoints with type validations and OpenApi documentation, safely and quickly.
This package contains BACKAN Server library
Build the backan
server with zero config.
🔑 Installation
npm install @backan/server
pnpm i @backan/server
yarn add @backan/server
📈 usage
import {server} from '@backan/server'
import {App} from 'backan'
const app = new App( {
version : '1.0.0',
title : 'BACKAN sample application',
})
server({ app })
⚙️ Configuration
The backan
server comes ready to use without any configuration, but this does not mean that we can configure certain aspects of the server if we want.
Here is a list of the available options.
type ServerOpts = {
app: App<Env>,
port?: number
hostname?: string
protocol?: 'http' | 'https',
autoPort?: boolean
allowFlags?: boolean
onSuccess?: ( info: ServerInfo ) => Promise<void>
onError?: ( opts: {
/**
* Server error id.
*/
id: ServerError,
/**
* Error catched in process.
*/
error: unknown,
/**
* Data info of server.
*/
data: ServerInfo
} ) => Promise<void>
onExit?: ( opts: {
/**
* Data info of server.
*/
data: ServerInfo
} ) => Promise<void>
}
type ServerInfo = {
hostname: string
port: number
protocol: string
url: string
}
💡 Examples
Zero config
import { server } from '@backan/server'
import app from './app.js'
await server({ app })
Fully customized
import { server } from '@backan/server'
import app from './app.js'
await server( {
app : app,
hostname : 'localhost',
protocol : 'http',
port : 1312,
autoPort : true,
allowFlags : true,
onError : async ( { id, error } ) => {
if( id === 'UNEXPECTED' ) console.error( '🐦💔 UNEXPECTED Error' )
else if( id === 'PORTS-NOT-AVAILABLE' ) console.error( '🐦💥🚢 No ports availables' )
else if( id === 'PORT-NOT-AVAILABLE' ) console.error( '🐦💥🚢 No port available' )
else if( id === 'HOSTNAME-NOT-VALID' ) console.error( '🐦💥🌐 Hostname not available' )
console.error( '\n',error )
},
onSuccess : async ( info ) => {
console.info( '🐦✅ Server info', info )
},
onExit : async () => {
console.warn( '\n\n🐦👋 Fly High Pigeon\n' )
},
} )
More from Backan
👨💻 Development
BACKAN is an open-source project and its development is open to anyone who wants to participate.
☕ Donate
Help us to develop more interesting things.
📜 License
This software is licensed with GPL-3.0.
🐦 About us
PigeonPosse is a ✨ code development collective ✨ focused on creating practical and interesting tools that help developers and users enjoy a more agile and comfortable experience. Our projects cover various programming sectors and we do not have a thematic limitation in terms of projects.
Collaborators