-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (42 loc) · 1.27 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const util = require('util');
const express = require('express');
const cors = require('cors');
const log = require('loglevel');
const AWS = require('aws-sdk');
log.setLevel(process.env.LOG_LEVEL || 'warn');
const ECS = new AWS.ECS();
const runTask = util.promisify(ECS.runTask).bind(ECS);
const app = express();
app.use(express.json());
app.use(cors({origin: true, credentials: true}));
app.get('/ping', (req, res) => {
res.send('pong');
});
app.get('/task', async (req, res, next) => {
try {
res.json(
await runTask({
cluster: process.env.FARGATE_CLUSTER,
launchType: 'FARGATE',
taskDefinition: 'Task1',
count: 1,
platformVersion: 'LATEST',
networkConfiguration: {
awsvpcConfiguration: {
subnets: process.env.SUBNETS.split(','),
securityGroups: process.env.SECURITY_GROUP.split(','),
},
},
})
);
} catch (err) {
next(err);
}
});
app.use((err, req, res, next) => {
log.error(err);
res.status(500).send(process.env.NODE_ENV == 'development' ? err.stack : 'Server Error');
next;
});
module.exports = app;