-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
29 lines (25 loc) · 843 Bytes
/
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
const express = require('express');
const cors = require('cors');
const pem = require('pem');
const https = require('https');
const app = express();
// Set up cross-origin permissions for mixmax.com
const corsOptions = {
origin: /^[^.\s]+\.mixmax\.com$/,
credentials: true
};
// Define API routes and middleware
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 || 9146);
} else {
// Create self-signed https certificate
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 || 9146);
});
}