Implement /api/v1/instance/peers (#2913)
* Implement /api/v1/instance/peers * Use punycode * Remove Cache-Control * Rename
This commit is contained in:
		
							parent
							
								
									99da4f9839
								
							
						
					
					
						commit
						072492c29b
					
				
					 2 changed files with 16 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -46,6 +46,8 @@ router.post('/signin', require('./private/signin').default);
 | 
			
		|||
router.use(require('./service/github').routes());
 | 
			
		||||
router.use(require('./service/twitter').routes());
 | 
			
		||||
 | 
			
		||||
router.use(require('./mastodon').routes());
 | 
			
		||||
 | 
			
		||||
// Return 404 for unknown API
 | 
			
		||||
router.all('*', async ctx => {
 | 
			
		||||
	ctx.status = 404;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								src/server/api/mastodon.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/server/api/mastodon.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
import * as Router from 'koa-router';
 | 
			
		||||
import User from '../../models/user';
 | 
			
		||||
import { toASCII } from 'punycode';
 | 
			
		||||
 | 
			
		||||
// Init router
 | 
			
		||||
const router = new Router();
 | 
			
		||||
 | 
			
		||||
router.get('/v1/instance/peers', async ctx => {
 | 
			
		||||
	const peers = await User.distinct('host', { host: { $ne: null } }) as any as string[];
 | 
			
		||||
	const punyCodes = peers.map(peer => toASCII(peer));
 | 
			
		||||
	ctx.body = punyCodes;
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
module.exports = router;
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue