-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
e8c6686
commit dc5b453
Showing
19 changed files
with
8,599 additions
and
64 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
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,29 @@ | ||
const _ = require('lodash') | ||
const products = require('./mock/_products') | ||
|
||
module.exports = function apiMiddleware(app) { | ||
// returning products | ||
app.get('/api/product/list', (req, res) => { | ||
res.json({ payload: products }).end() | ||
}) | ||
|
||
// get single product by sku | ||
app.get('/api/product/:id', (req, res) => { | ||
const id = parseInt(req.params.id, 10) | ||
const product = _.find(products, { id: id }) | ||
if (!product) { | ||
return res | ||
.status(404) | ||
.json({ error: { message: 'Product not found' } }) | ||
.end() | ||
} | ||
return res.json({ payload: product }).end() | ||
}) | ||
|
||
app.all('/api/*', (req, res) => | ||
res | ||
.status(404) | ||
.json({ error: { message: 'Not found' } }) | ||
.end() | ||
) | ||
} |
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,18 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIC9jCCAd6gAwIBAgIJAK0BJrHaPZgUMA0GCSqGSIb3DQEBBQUAMBYxFDASBgNV | ||
BAMMCyoubG9jYWxob3N0MB4XDTE3MDYxODE5MjkxN1oXDTI3MDYxNjE5MjkxN1ow | ||
FjEUMBIGA1UEAwwLKi5sb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw | ||
ggEKAoIBAQDJyQYsGGqVmAAbnnIE8VoXc79DEFDa+Lhw56WVFB7KOz6Y7a9+fJvW | ||
UqrQaNQ5TWKG671XOy0ZUNAHuAowsHZTRFAgnjHtedq3DybBhy/jJtdAALQvg/rJ | ||
hH1saEGr8u3eF00scBYusXjkj7u6DVFsvgPyWgXasTxV71HTDESuBMfi8yUQ4ceq | ||
1d1LB6TOPMZXEJN8SsNO6oMzIj9aEpa0AP7IhujcheaZqDqA2echDCmYkMx8ozq/ | ||
xu8vxlVKtg8HRtCOt3evthr9NCZFZNmqDUVLCL0AVroRTBT4k7rEkN9Mtr4WKEwS | ||
SAwoutSJKadhkwTRlKhWk/EvCj4O1PunAgMBAAGjRzBFMAsGA1UdDwQEAwIEMDAT | ||
BgNVHSUEDDAKBggrBgEFBQcDATAhBgNVHREEGjAYggsqLmxvY2FsaG9zdIIJbG9j | ||
YWxob3N0MA0GCSqGSIb3DQEBBQUAA4IBAQC/Kyxu6avtXPaaEQKuDc1Z6qO2SWis | ||
CqTXr4lsuZTnK+RGI3N3upkh/WbKiVhLSqLP51WTyM+ekaW0Vjg8Ce7ph3deLVmF | ||
WtNKmFqlUcEI4vsM8N2Tt+c5XRqlPfvNuLFlIdkj564cpF6oo8FvMI2LueXM+9N5 | ||
N6/c0wpjQyhYN80VmDET31rSmqFmj9NpmZUHeC/B8qOllawVGNVteMsHYP5kdmp1 | ||
LD0905T9umSWw0oCVW4HP6C8u2M6N03CkuvRZPbVjqf6porz5HRp+/NVK/3E3mfc | ||
HX9Gineyo6RvwbsFCWQe2WHDEz9C6c/WPnbeG6nSoEpS8tA5JkYofUAi | ||
-----END CERTIFICATE----- |
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,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAo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ddK2+uk+KqruJghJ7gW8XI3OrL | ||
C8RaB1ulXQKBgAQsRHu46rNm/bhQFuql8fcmlUrZu5cBirFqYIw7Dr0AQM9StLV1 | ||
F/D9UtdJpOSFcqV2/c8UZHl6H8mbWMnlm0CxOdmXtdfWmE2ALfAxcWZO46Y7kIXk | ||
h982ESYPqS3JrtBr0eSj5W9aj2yaHgOA9WMq7BR7mKu2lRHz/yExo6zlAoGAeQFX | ||
KUBki7vgNaFx4rYfyOeDOoi/1pR7ZDMKAFSC/I2LLuAKYTSdtr23JdjorRxkR75S | ||
XCRNDp0SIxRHXA1GrzavQsx/JPI/whqITBosM6R8eNqwnVfPrDGAeopSh7Nd5bJY | ||
lMC1qJX11Y78OMYOcaQxTW9E/qKWEOdiQF8JGeECgYBm9yty65kd3IsHmmnXz6PN | ||
Hwaw5p3XTJkQT2uYM6enPrvslMVxEkl1JUMeG68XrglnJMdv/opnoA0XG5Ee02bw | ||
m3Zc6kUsnSgQdnnncltbEptVAf8FNiOMz4z5lLeFpRLbYSTU6vo99yshDguMsgEd | ||
gxqV07IHTfDpwclZsItWOw== | ||
-----END PRIVATE KEY----- |
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,57 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const spdy = require('spdy') | ||
const cors = require('cors') | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
const compression = require('compression') | ||
const apiMiddleware = require('./api') | ||
|
||
const app = express() | ||
|
||
app.use(cors()) | ||
// Ensure secure | ||
app.all('*', (req, res, next) => { | ||
if (req.secure) return next() | ||
res.redirect( | ||
`https://${req.hostname}:${process.env.PORT_HTTPS || 3443}${req.url}` | ||
) | ||
}) | ||
|
||
// Setup body parsing | ||
app.use(bodyParser.urlencoded({ extended: true })) | ||
app.use(bodyParser.json()) | ||
|
||
apiMiddleware(app) | ||
|
||
app.use(compression({ threshold: 0 })) | ||
|
||
const https = spdy.createServer( | ||
{ | ||
requestCert: false, | ||
rejectUnauthorized: false, | ||
key: fs.readFileSync(path.resolve(__dirname, './certificate/key.pem')), | ||
cert: fs.readFileSync(path.resolve(__dirname, './certificate/cert.pem')) | ||
}, | ||
app | ||
) | ||
|
||
https.listen(process.env.PORT_HTTPS || 3443, error => { | ||
if (error) { | ||
console.error(error) | ||
return process.exit(1) | ||
} | ||
return console.log( | ||
`App running in HTTPS on port: ${process.env.PORT_HTTPS || 3443}.` | ||
) | ||
}) | ||
|
||
app.listen(process.env.PORT || 8081, error => { | ||
if (error) { | ||
console.error(error) | ||
return process.exit(1) | ||
} | ||
return console.log( | ||
`App running in HTTP on port: ${process.env.PORT || 8081}.` | ||
) | ||
}) |
Oops, something went wrong.