标题可能写的不怎么好。
我想给自己用 Koa 写的 API 程序里弄一个和GitHub API 一样的 API 目录之类的东西,可是我不知道如何在后端里获取自己服务器的域名。
比如我的服务器的域名为 example.com ,那么内容应该是这样的:
{
'example1': 'http://example.com/api/example1/',
'example2': 'http://example.com/api/example2/'
}
而别人在使用我的项目时,域名为 qwertyu.io ,那么应该是这样的:
{
'example1': 'http://qwertyu.io/api/example1/',
'example2': 'http://qwertyu.io/api/example2/'
}
可是就在这域名上我不知道该怎么做,是要人工配置定义域名还是有其它的轮子可以这么做?