mirror of https://gitgud.io/cncanon/sg-proxy.git
Add basic token sanity checks
This commit is contained in:
parent
a60f37047e
commit
3c20b3b07f
10
main.js
10
main.js
|
@ -2,6 +2,7 @@ require("dotenv").config();
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const { exit } = require("process");
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
@ -115,5 +116,14 @@ process.on('unhandledRejection', (reason, promise) => {
|
||||||
console.error('Unhandled Promise Rejection:', reason);
|
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;
|
const port = process.env.PORT || 3000;
|
||||||
app.listen(port, () => console.log(`Server listening on port ${port}`));
|
app.listen(port, () => console.log(`Server listening on port ${port}`));
|
Loading…
Reference in New Issue