From 3c20b3b07fe8e2b31a103db6873c3cca4066ee24 Mon Sep 17 00:00:00 2001 From: CncAnon Date: Mon, 28 Aug 2023 13:50:56 +0300 Subject: [PATCH] Add basic token sanity checks --- main.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.js b/main.js index a2b47dd..6f65f3a 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ require("dotenv").config(); const express = require('express'); const axios = require('axios'); +const { exit } = require("process"); const app = express(); app.use(express.json()); @@ -115,5 +116,14 @@ process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Promise Rejection:', reason); }); +if (!API_TOKEN) { + console.error("SourceGraph API token not found! Create a file named '.env' and put your token there as an API_TOKEN. See .env.example for an example."); + exit(); +} +else if (API_TOKEN.indexOf("sgp_") == -1) { + console.error("Invalid SourceGraph API token! Make sure you copied the whole token starting with sgp_, like 'sgp-blablabla'."); + exit(); +} + const port = process.env.PORT || 3000; app.listen(port, () => console.log(`Server listening on port ${port}`)); \ No newline at end of file