"Speedtest.net servers in JSON" doc page

parent 76924ac9
...@@ -325,3 +325,14 @@ app.use((err, req: Request, res: Response, next: NextFunction) => { ...@@ -325,3 +325,14 @@ app.use((err, req: Request, res: Response, next: NextFunction) => {
export default app; export default app;
export { getCountryName }; export { getCountryName };
/**
* Data return formats, used for ?format query parameter on some routes.
*/
enum DataReturnFormat {
Html = "html",
Json = "json",
Jsonp = "jsonp",
}
export { DataReturnFormat };
\ No newline at end of file
...@@ -97,11 +97,7 @@ router.get("/ip", (req: Request, res: Response, next: NextFunction) => { ...@@ -97,11 +97,7 @@ router.get("/ip", (req: Request, res: Response, next: NextFunction) => {
}); });
}); });
enum DataReturnFormat { import { DataReturnFormat } from "../app";
Html = "html",
Json = "json",
Jsonp = "jsonp",
}
/** /**
* Browse Speedtest.net servers * Browse Speedtest.net servers
...@@ -146,6 +142,7 @@ router.get("/speedtest-servers/", (req: Request, res: Response, next: NextFuncti ...@@ -146,6 +142,7 @@ router.get("/speedtest-servers/", (req: Request, res: Response, next: NextFuncti
}) })
.then(servers => { .then(servers => {
if(format === DataReturnFormat.Json) { if(format === DataReturnFormat.Json) {
res.set("Access-Control-Allow-Origin", "*");
res.json(servers); res.json(servers);
} else if(format === DataReturnFormat.Jsonp) { } else if(format === DataReturnFormat.Jsonp) {
res.jsonp(servers); res.jsonp(servers);
......
...@@ -50,4 +50,11 @@ router.get("/docs/dns-demo/", (req: Request, res: Response, next: NextFunction) ...@@ -50,4 +50,11 @@ router.get("/docs/dns-demo/", (req: Request, res: Response, next: NextFunction)
}); });
}); });
router.get("/docs/speedtest-servers-json/", (req: Request, res: Response, next: NextFunction) => {
res.render("docs/speedtest-servers-json.twig", {
"canonical_url": "/docs/speedtest-servers-json/",
"title": "List of Speedtest.net servers in JSON",
});
});
export const HomeController: Router = router; export const HomeController: Router = router;
...@@ -82,6 +82,7 @@ location: <a href="https://peeringdb.com/api/net/291" class="text-dark">https:// ...@@ -82,6 +82,7 @@ location: <a href="https://peeringdb.com/api/net/291" class="text-dark">https://
<ul> <ul>
<li><a href="/docs/tor-relay-list/">Tor relay list in JSON</a></li> <li><a href="/docs/tor-relay-list/">Tor relay list in JSON</a></li>
<li><a href="/docs/speedtest-servers-json/">List of Speedtest.net servers in JSON</a></li>
</ul> </ul>
<h2>DNS-over-HTTPS</h2> <h2>DNS-over-HTTPS</h2>
......
{% extends 'layouts/default.twig' %}
{% block body %}
<h1>{{ title }}</h1>
<h2>Downloads</h2>
<ul>
<li><a href="/explore/speedtest-servers?format=json">JSON format</a></li>
<li><a href="/explore/speedtest-servers/">HTML format</a></li>
<li><a href="https://www.speedtest.net/speedtest-servers.php">XML format</a> (original)</li>
</ul>
<hr>
<p><a href="/docs/">Go back to documentation</a></p>
{% endblock %}
\ No newline at end of file
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</tbody> </tbody>
</table> </table>
<p>Also available in <a href="/explore/speedtest-servers?format=json">JSON</a> and <a href="https://www.speedtest.net/speedtest-servers.php">XML</a>.</p> <p>Also available in <a href="/docs/speedtest-servers-json/">JSON</a> and <a href="https://www.speedtest.net/speedtest-servers.php">XML</a>.</p>
{% endblock %} {% endblock %}
{% block javascripts %} {% block javascripts %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment