Use --locationbase to specify the path used by the reverse proxy Updated deezer-js to 1.3.8
		
			
				
	
	
		
			47 lines
		
	
	
		
			940 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			940 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import type { Application } from 'express'
 | 
						|
import type { ApiHandler } from '../../types'
 | 
						|
import getEndpoints from './get'
 | 
						|
import deleteEndpoints from './delete'
 | 
						|
import postEndpoints from './post'
 | 
						|
import patchEndpoints from './patch'
 | 
						|
 | 
						|
const prependApiPath = (path: string) => `*/api${path}`
 | 
						|
 | 
						|
interface Method {
 | 
						|
	method: string
 | 
						|
	endpoints: ApiHandler[]
 | 
						|
}
 | 
						|
 | 
						|
const methods: Method[] = [
 | 
						|
	{
 | 
						|
		method: 'get',
 | 
						|
		endpoints: getEndpoints
 | 
						|
	},
 | 
						|
	{
 | 
						|
		method: 'delete',
 | 
						|
		endpoints: deleteEndpoints
 | 
						|
	},
 | 
						|
	{
 | 
						|
		method: 'post',
 | 
						|
		endpoints: postEndpoints
 | 
						|
	},
 | 
						|
	{
 | 
						|
		method: 'patch',
 | 
						|
		endpoints: patchEndpoints
 | 
						|
	}
 | 
						|
]
 | 
						|
 | 
						|
export function registerApis(app: Application) {
 | 
						|
	methods.forEach(({ method, endpoints }) => {
 | 
						|
		endpoints.forEach(endpoint => {
 | 
						|
			// @ts-expect-error
 | 
						|
			app[method](prependApiPath(endpoint.path), endpoint.handler)
 | 
						|
		})
 | 
						|
	})
 | 
						|
 | 
						|
	// Fallback, for SPA mode
 | 
						|
	app.get('*/api*', (_, res) => {
 | 
						|
		res.send({ error: "API endpoint doesn't exist" })
 | 
						|
	})
 | 
						|
}
 |