Fix filepath

This commit is contained in:
Daniel Kluge 2022-05-07 16:39:01 +02:00
parent 1a646d1dff
commit a6418e82bf

View File

@ -14,7 +14,8 @@ const port = 8080;
let state = "code"; let state = "code";
// Read and parse JSON. There is no __dirname for modules // Read and parse JSON. There is no __dirname for modules
const secrets = JSON.parse(readFileSync(`${dirname(fileURLToPath(import.meta.url))}/../secrets.json`, "utf8")); const secretsFile = `${dirname(fileURLToPath(import.meta.url))}/../secrets.json`;
const secrets = JSON.parse(readFileSync(secretsFile, "utf8"));
// Express route that prints request body and query parameters // Express route that prints request body and query parameters
app.use("/", (req, res) => { app.use("/", (req, res) => {
@ -64,7 +65,7 @@ async function getToken(googleResponse) {
console.log("Got the token!"); console.log("Got the token!");
console.log("Writing token to secrets..."); console.log("Writing token to secrets...");
secrets.refreshToken = data.refresh_token; secrets.refreshToken = data.refresh_token;
writeFileSync("./secrets.json", JSON.stringify(secrets)); writeFileSync(secretsFile, JSON.stringify(secrets, null, 2));
console.log("Done!"); console.log("Done!");
server.close(); server.close();