Skip to content

Commit

Permalink
Lineant CORS support
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCreator committed Jan 13, 2020
1 parent ba07ad3 commit 9fea742
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 49 deletions.
4 changes: 2 additions & 2 deletions api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const cacheControl = require("./config/cacheControl");
let app = require("./src/app-setup");

// Setup the routes
app.get("/api/v1/mail/list", require("./src/api/mailList"));
app.get("/api/v1/mail/list", require("./src/api/mailList"));
app.get("/api/v1/mail/getInfo", require("./src/api/mailGetInfo"));
app.get("/api/v1/mail/getHtml", require("./src/api/mailGetHtml"));

// Legacy fallback behaviour -
// Note this is to be deprecated (after updating UI)
app.get("/api/v1/mail/getKey", require("./src/api/mailGetInfo"));
app.get("/api/v1/mail/getKey", require("./src/api/mailGetInfo"));

// Static regex
const staticRegex = /static\/(js|css|img)\/(.+)\.([a-zA-Z0-9]+)\.(css|js|png|gif)/g;
Expand Down
4 changes: 2 additions & 2 deletions api/config/mailgunConfig.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// API key and valid mailgun domain supported (using sandbox)
//
module.exports = {
"apiKey" : "${MAILGUN_API_KEY}",
"apiKey" : "${MAILGUN_API_KEY}",
"emailDomain" : "${MAILGUN_EMAIL_DOMAIN}",
"corsOrigin" : "https://${WEBSITE_DOMAIN}"
//"corsOrigin" : "*"
}
61 changes: 31 additions & 30 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
{
"name": "inboxkitten-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.0.5",
"kittenrouter": "^1.0.3",
"validator": "^10.7.0"
},
"devDependencies": {
"delay": "^4.0.0",
"mailgun-js": "^0.20.0",
"md5": "^2.2.1",
"mocha": "^5.2.0",
"shortid": "^2.2.13",
"uuid": "^3.3.2",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.0"
},
"scripts": {
"test": "mocha",
"start": "node app.js",
"build-cloudflare": "webpack --mode production cloudflare.js"
},
"author": "",
"license": "MIT"
"name": "inboxkitten-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"express": "^4.16.3",
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.0.5",
"kittenrouter": "^1.0.3",
"validator": "^10.7.0"
},
"devDependencies": {
"delay": "^4.0.0",
"mailgun-js": "^0.20.0",
"md5": "^2.2.1",
"mocha": "^5.2.0",
"shortid": "^2.2.13",
"uuid": "^3.3.2",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.0"
},
"scripts": {
"test": "mocha",
"start": "node app.js",
"build-cloudflare": "webpack --mode production cloudflare.js"
},
"author": "",
"license": "MIT"
}
17 changes: 2 additions & 15 deletions api/src/app-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@
// Dependencies loading
const express = require("express");
const bodyParser = require("body-parser");
const cors = require('cors');
const mailgunConfig = require("../config/mailgunConfig");

// Initializing the express app
const app = express();

// Allow cross site requests (for now)
app.use(function (req, res, next){
res.setHeader("Access-Control-Allow-Origin", mailgunConfig.corsOrigin);
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);

// Pass to next layer of middleware
next();
});
app.use(cors());

// Setup JSON encoding
app.use(bodyParser.json());
Expand Down

0 comments on commit 9fea742

Please sign in to comment.