-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (29 loc) · 1019 Bytes
/
app.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
const express = require("express");
const bodyParser = require("body-parser");
const sync = require("synchronize");
const cors = require("cors");
const app = express();
// Use fibers in all routes so we can use sync.await() to make async code easier to work with.
app.use((req, res, next) => {
sync.fiber(next);
});
// Since Mixmax calls this API directly from the client-side, it must be whitelisted.
const corsOptions = {
origin: /^[^.\s]+\.mixmax\.com$/,
credentials: true
};
app.get("/typeahead", cors(corsOptions), require("./api/typeahead"));
app.get("/resolver", cors(corsOptions), require("./api/resolver"));
if (process.env.NODE_ENV === "production") {
app.listen(process.env.PORT || 9145);
} else {
const pem = require("pem");
const https = require("https");
pem.createCertificate({ days: 1, selfSigned: true }, (err, keys) => {
if (err) throw err;
https.createServer({
key: keys.serviceKey,
cert: keys.certificate
}, app).listen(process.env.PORT || 9145);
});
}