Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env-cmdrc-template
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"test": {
"ENV": "TEST",
"PORT": "3000",
"SSL_CERT": "",
"SSL_KEY": "",
"SENDGRID_API_KEY": "SG.MOCK_API_TOKEN",
"SENDGRID_MAIL_FROM": "MOCK_MAIL_FROM",
"SENDGRID_CONFIRMATION_TEMPLATE": "SG.CONFIRMATION_TEMPLATE",
Expand Down
6 changes: 4 additions & 2 deletions config/.env.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### Switcher API
SSL_CERT=
SSL_KEY=
MONGODB_URI=mongodb://mongodb:27017/switcher-api
JWT_SECRET=[CHANGE_IT]
RESOURCE_SECRET=[CHANGE_IT]
Expand All @@ -16,6 +18,6 @@ METRICS_MAX_PAGE=50
GOOGLE_SKIP_AUTH=true

### Switcher Management
SWITCHERAPI_URL=http://10.0.0.2:3000
SM_IP=http://10.0.0.2
SWITCHERAPI_URL=http://localhost:3000
SM_IP=http://localhost
#SWITCHERSLACKAPP_URL=[SWITCHER_SLACK_APP_ENDPOINT]/slack/install
17 changes: 16 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ version: '3.8'
volumes:
mongodb_data:
driver: local
switcherapi-tls:
driver: local
driver_opts:
o: bind
type: none
device: "[CHANGE_IT]"

networks:
backend:
Expand Down Expand Up @@ -33,6 +39,9 @@ services:
- NODE_ENV=development
- PORT=3000
- ENV=${ENV}
- SSL_KEY=${SSL_KEY}
- SSL_CERT=${SSL_CERT}

- MONGODB_URI=${MONGODB_URI}
- SENDGRID_API_KEY=${SENDGRID_API_KEY}
- SENDGRID_MAIL_FROM=${SENDGRID_MAIL_FROM}
Expand Down Expand Up @@ -67,13 +76,19 @@ services:
- SWITCHER_SLACK_JWT_SECRET=${SWITCHER_SLACK_JWT_SECRET}
depends_on:
- mongodb
volumes:
- switcherapi-tls:/etc/certs

switchermanagement:
image: trackerforce/switcher-management
container_name: switchermanagement
command: /bin/sh -c "setup.sh"
# Enable SSL with "./setup.sh true"
command: ["/bin/sh", "-c", "./setup.sh"]
ports:
- 443:443
- 80:80
volumes:
- switcherapi-tls:/etc/nginx/conf.d
networks:
- backend
environment:
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sonar.javascript.lcov.reportPaths=coverage/lcov.info

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=src
sonar.exclusions=src/api-docs/**, src/helpers/timed-match/match-proc.js
sonar.exclusions=src/api-docs/**, src/app-server.js, src/helpers/timed-match/match-proc.js
sonar.tests=tests
sonar.language=js

Expand Down
18 changes: 18 additions & 0 deletions src/app-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import https from 'https';
import http from 'http';
import fs from 'fs';

export const createServer = (app) => {
if (process.env.SSL_CERT && process.env.SSL_KEY) {
const options = {
key: fs.readFileSync(process.env.SSL_KEY),
cert: fs.readFileSync(process.env.SSL_CERT)
};

console.log('SSL enabled');
return https.createServer(options, app);
}

console.log('SSL disabled');
return http.createServer(app);
};
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import slackRouter from './routers/slack';
import schema from './client/schema';
import { appAuth, auth, resourcesAuth, slackAuth } from './middleware/auth';
import { clientLimiter, defaultLimiter } from './middleware/limiter';
import { createServer } from './app-server';

const app = express();
app.use(express.json());
Expand Down Expand Up @@ -110,4 +111,4 @@ app.get('*', (_req, res) => {
res.status(404).send({ error: 'Operation not found' });
});

export default app;
export default createServer(app);