-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
80 lines (67 loc) · 2.31 KB
/
server.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
____ _
/ ___| ___ _ __ | |__ ___ _ __
| | _ / _ \| '_ \| '_ \ / _ | '__|
| |_| | (_) | |_) | | | | __| |
\____|\___/| .__/|_| |_|\___|_|
|_|
docs.gopher.email
Need help? Get in touch!
slack: slackin.gopheremail.com
email: [email protected]
*/
require("dotenv").config();
const debug = require("debug")("gopher-express");
const express = require("express");
const app = express();
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const gopherUtils = require("./lib/_gopherUtils");
const gopherAuth = require("./routes/_gopherAuth");
const config = require("./lib/_config");
app.use(cookieParser());
// Keep public/index.html for familiarity
app.set("view engine", "html");
app.engine("html", ejs.renderFile);
app.set("views", __dirname + "/public");
/**
*
* Your extension interacts with Gopher mainly via webhooks.
* Open up /routes/gopherWebhooks.js to learn more.
*
*/
const webhooks = require("./routes/gopherWebhooks");
app.use("/webhooks", webhooks);
/**
*
* These pages can be used to welcome the user, updating
* settings and any other task that requires a web-ui.
* Edit public/index.html, public/settings.html, public/app.js and public/app.css to customize.
*
*/
const templateVars = {
sandboxUrl: config.gopherAdmin + "sandbox/" + config.extensionId + "?devtour=1",
testEmail: "test@" + process.env.EXT_SUBDOMAIN + ".gopher.email",
extDomain: process.env.EXT_SUBDOMAIN + ".gopher.email"
}
app.get("/", gopherUtils.requireLogin, (req, res) => {
res.render("index", templateVars);
});
app.get("/settings", gopherUtils.requireLogin, (req, res) => {
res.render("settings", templateVars);
});
/**
*
* A few examples of using the API client.
* View more API methods https://github.com/gopherhq/gopherhq-js
*
*/
const exampleRoutes = require("./routes/gopherApi");
app.use(exampleRoutes);
app.use("/auth", gopherAuth);
app.use("/utils.js", gopherUtils.requireLogin, gopherUtils.jsTokenizer); // automatically populated with config values
app.use(express.static("public"));
const listener = app.listen(process.env.PORT || 3011, function() {
console.log("Your app is listening on port " + listener.address().port);
});