forked from talkjs/talkjs-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (32 loc) · 1.04 KB
/
Copy pathapp.js
File metadata and controls
38 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require("dotenv").config()
var express = require("express");
var path = require("path");
var app = express();
var bodyParser = require("body-parser");
// bodyParser trick to ensure we get access to the raw request body, taken from
// https://flaviocopes.com/express-get-raw-body/
app.use(bodyParser.json({
verify: (req, res, buf) => {
req.rawBody = buf
}
}));
app.use(express.urlencoded({
extended: false
}));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
// Set your TalkJS appId in the .env file
// Your appId can be found on your TalkJS Dashboard: https://talkjs.com/dashboard/
const appId = process.env.APPID;
// Make the appId accessible in all views
app.use((req, res, next) => {
app.locals.appId = appId;
next();
})
// Import our routes for the chat and webhooks
var chatRoutes = require("./routes/chatRoutes");
var webhookRoutes = require("./routes/webhooks");
// Apply the routes for the appropriate paths
app.use("/chat", chatRoutes);
app.use("/talkjs", webhookRoutes);
module.exports = app;