Skip to content

Commit 7088e05

Browse files
thehabesCopilot
andauthored
Automated Token Refreshes (Human Version) (#23)
* This should do it, and with updated packages * oo fix these errors * Changes from testing * Update tokens.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update __tests__/mount.test.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * touchup --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f30e71c commit 7088e05

9 files changed

Lines changed: 3950 additions & 3131 deletions

File tree

__tests__/mount.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import app from "../app.js"
55
beforeEach(() => {
66
// This comes from tokens.js in the app.js import. This apps tries to read env.ACCESS_TOKEN to refresh expired tokens.
77
// We don't care whether or not the token is expired here, so let's just state we don't care about tokens in tests.
8-
updateExpiredToken = jest.fn(() => true)
8+
checkAccessToken = jest.fn((req, res, next) => next())
99
isTokenExpired = jest.fn(() => false)
1010
})
1111

app.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import updateRouter from "./routes/update.js"
1212
import deleteRouter from "./routes/delete.js"
1313
import overwriteRouter from "./routes/overwrite.js"
1414
import cors from "cors"
15-
import {updateExpiredToken } from "./tokens.js"
1615

17-
// Check for and update token on app start
18-
updateExpiredToken()
1916
let app = express()
2017
app.use(express.json())
18+
app.use(express.text())
2119
if(process.env.OPEN_API_CORS !== "false") {
2220
// This enables CORS for all requests. We may want to update this in the future and only apply to some routes.
2321
app.use(cors())
@@ -33,26 +31,29 @@ app.use(express.static(path.join(__dirname, 'public')))
3331
*/
3432
const corsAllowedOrigins = process.env.OPEN_API_CORS == "true" ? "*" : process.env.SERVICES_ORIGINS.split(",")
3533
app.use(cors({
36-
"methods" : "GET",
37-
"allowedHeaders" : [
38-
'Content-Type',
39-
'Content-Length',
40-
'Allow',
41-
'Authorization',
42-
'Location',
43-
'ETag',
44-
'Connection',
45-
'Keep-Alive',
46-
'Date',
47-
'Cache-Control',
48-
'Last-Modified',
49-
'Link',
50-
'X-HTTP-Method-Override'
51-
],
52-
"exposedHeaders" : "*",
53-
"origin" : corsAllowedOrigins,
54-
"maxAge" : "600"
55-
}))
34+
"methods" : "GET,OPTIONS,HEAD,PUT,PATCH,DELETE,POST",
35+
"allowedHeaders" : [
36+
'Content-Type',
37+
'Content-Length',
38+
'Allow',
39+
'Authorization',
40+
'Location',
41+
'ETag',
42+
'Connection',
43+
'Keep-Alive',
44+
'Date',
45+
'Cache-Control',
46+
'Last-Modified',
47+
'Link',
48+
'X-HTTP-Method-Override',
49+
'Origin',
50+
'Referrer',
51+
'User-Agent'
52+
],
53+
"exposedHeaders" : "*",
54+
"origin" : corsAllowedOrigins,
55+
"maxAge" : "600"
56+
}))
5657

5758
/**
5859
* Prepare the response Access-Control-Allow-Origin header before entering routes.

0 commit comments

Comments
 (0)