Spaces:
Sleeping
Sleeping
Update src/index.js
Browse files- src/index.js +10 -7
src/index.js
CHANGED
|
@@ -18,16 +18,19 @@ for (const key of REQUIRED_ENV) {
|
|
| 18 |
|
| 19 |
const app = express()
|
| 20 |
|
| 21 |
-
// Raw body
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
app.use('/', router)
|
| 28 |
|
| 29 |
const PORT = process.env.PORT || 7860
|
| 30 |
-
|
| 31 |
app.listen(PORT, () => {
|
| 32 |
console.log(`[startup] gateway-services running on port ${PORT} — ${new Date().toISOString()}`)
|
| 33 |
-
})
|
|
|
|
| 18 |
|
| 19 |
const app = express()
|
| 20 |
|
| 21 |
+
// Raw body for /interactions — must come first, before any JSON middleware.
|
| 22 |
+
// type: '*/*' captures whatever Content-Type Discord sends.
|
| 23 |
+
app.use('/interactions', express.raw({ type: '*/*' }))
|
| 24 |
+
|
| 25 |
+
// JSON body for every other route — skip /interactions so the raw Buffer is preserved.
|
| 26 |
+
app.use((req, res, next) => {
|
| 27 |
+
if (req.path === '/interactions') return next()
|
| 28 |
+
express.json()(req, res, next)
|
| 29 |
+
})
|
| 30 |
|
| 31 |
app.use('/', router)
|
| 32 |
|
| 33 |
const PORT = process.env.PORT || 7860
|
|
|
|
| 34 |
app.listen(PORT, () => {
|
| 35 |
console.log(`[startup] gateway-services running on port ${PORT} — ${new Date().toISOString()}`)
|
| 36 |
+
})
|