-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
// log to files | ||
const logger = require('console-files') | ||
// handle app authentication to Store API | ||
// https://github.com/ecomclub/ecomplus-app-sdk | ||
const { ecomAuth, ecomServerIps } = require('ecomplus-app-sdk') | ||
|
||
// web server with Express | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
const app = express() | ||
const port = process.env.PORT || 3000 | ||
|
||
app.use(bodyParser.urlencoded({ extended: false })) | ||
app.use(bodyParser.json()) | ||
|
||
app.use((req, res, next) => { | ||
if (req.baseUrl.startsWith('/ecom/') && process.env.NODE_ENV === 'production') { | ||
// check if request is comming from E-Com Plus servers | ||
if (ecomServerIps.indexOf(req.get('x-real-ip')) === -1) { | ||
res.status(403).send('Who are you? Unauthorized IP address') | ||
} else { | ||
next() | ||
} | ||
} else { | ||
// bypass | ||
next() | ||
} | ||
}) | ||
|
||
ecomAuth.then(appSdk => { | ||
// setup app routes | ||
require('./../routes/')(appSdk) | ||
}) | ||
|
||
app.listen(port) | ||
logger.log(`--> Starting web app on port :${port}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'use strict' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'use strict' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
// read app package.json | ||
const pkg = require('./../package.json') | ||
// setup Express router | ||
const router = require('express').Router() | ||
|
||
module.exports = appSdk => { | ||
// base routes for E-Com Plus Store API | ||
;[ 'auth-callback', 'webhook' ].forEach(route => { | ||
let filename = `/ecom/${route}` | ||
router.use(filename, require(`.${filename}`)(appSdk)) | ||
}) | ||
|
||
// show package info on domain root | ||
router.get('/', (req, res) => res.send(pkg)) | ||
|
||
/* Add custom app routes here */ | ||
} |