diff --git a/app.js b/app.js index 1e647dc..153f9fb 100644 --- a/app.js +++ b/app.js @@ -1,22 +1,24 @@ -'use strict'; -var express = require('express'); -var cors = require('express-cors') -var twilio = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN); - +"use strict"; +var express = require("express"); +var cors = require("express-cors"); +var twilio = require("twilio")( + process.env.TWILIO_ACCOUNT_SID, + process.env.TWILIO_AUTH_TOKEN +); var app = express(); - -app.use(cors({ - allowedOrigins: [process.env.ALLOWED_ORIGIN], - methods: ['GET'] -})); - +app.use( + cors({ + allowedOrigins: ["http://localhost:3000", "https://main.gameofdrones.kz"], + methods: ["GET"], + }) +); var cachedToken = null; -function getNewToken () { - twilio.tokens.create({}, function(err, token) { +function getNewToken() { + twilio.tokens.create({}, function (err, token) { if (!err && token) { cachedToken = token; } @@ -26,11 +28,11 @@ function getNewToken () { // fetch token initially getNewToken(); // refetch new token every 15 mins and save to cache -setInterval(getNewToken, 1000*60*10); +setInterval(getNewToken, 1000 * 60 * 10); -app.get('/', function (req, res) { +app.get("/", function (req, res) { if (!cachedToken) { - res.send(400, 'Problem getting ice servers data from Twilio') + res.send(400, "Problem getting ice servers data from Twilio"); } else { res.json(cachedToken.iceServers); } @@ -39,8 +41,8 @@ app.get('/', function (req, res) { var port = process.env.PORT || 3000; app.listen(port, function (err) { if (err) { - console.log('failed to start server', err); + console.log("failed to start server", err); } else { - console.log('started server on port:', port); + console.log("started server on port:", port); } -}); \ No newline at end of file +});