Skip to content

Commit f2a0ff8

Browse files
author
William
committed
Initial commit
1 parent 3d57496 commit f2a0ff8

File tree

95 files changed

+15171
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+15171
-0
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:16-alpine as template-private-api-nodejs
2+
RUN mkdir /home/app
3+
WORKDIR /home/app
4+
COPY . /home/app
5+
RUN apk add git
6+
RUN npm install --quiet
7+
VOLUME /tmp
8+
EXPOSE 80
9+
ENTRYPOINT node server.js

cluster.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const dotenv = require('dotenv');
2+
const cluster =require('cluster');
3+
const http = require('http');
4+
const getPort = require('get-port'); // TODO: Replace with "port-finder"?
5+
const os = require('os');
6+
const createApp = require('./src/app.js');
7+
8+
dotenv.config(); // Load environment vars
9+
10+
// Load app config.ini
11+
const DEFAULT_PORT = process.env.APP_PORT || process.env.PORT || 4000; // Configure server default PORT
12+
const MAX_TIMEOUT = 30 * 60 *1000; // Configure server max hard timeout 30m
13+
const NUM_CPUS = os.cpus().length || 1; // Configure number of threads
14+
15+
var server, app, port = null;
16+
17+
const events = {
18+
onInit: () => {
19+
console.log(`Node.js template Private API ${process.pid} - listening on port %s`, port);
20+
21+
if (process.emit) {
22+
process.emit('ready');
23+
}
24+
},
25+
onShutdown: () => {
26+
if (!app || !app.locals) {
27+
return;
28+
}
29+
30+
app.locals.discovery.unregister()
31+
.then(() => {
32+
console.log('Service unregistred!');
33+
process.exit(0);
34+
})
35+
.catch(console.error);
36+
}
37+
};
38+
39+
if (cluster.isMaster) {
40+
console.log(`Node.js template Private API ${process.pid} - master`);
41+
42+
for (let i = 0; i < NUM_CPUS; i++) {
43+
cluster.fork();
44+
}
45+
46+
cluster.on('exit', (worker, code, signal) => {
47+
console.log(`worker ${worker.process.pid} died`);
48+
});
49+
50+
cluster.on('disconnect', () => {
51+
console.log('worker disconnected');
52+
});
53+
}
54+
55+
/**
56+
* Bootstrap app
57+
*/
58+
const main = async () => {
59+
const getPortOptions = {
60+
port: parseInt(DEFAULT_PORT)
61+
};
62+
63+
port = 4000;
64+
65+
/*
66+
if (!port) {
67+
port = await getPort(getPortOptions);
68+
}
69+
*/
70+
71+
app = createApp(port);
72+
server = http.createServer(app);
73+
server.setTimeout(MAX_TIMEOUT);
74+
server.listen(port, events.onInit);
75+
};
76+
77+
process.on('SIGHUP', events.onShutdown);
78+
process.on('SIGINT', events.onShutdown);
79+
process.on('SIGTERM', events.onShutdown);
80+
81+
if (!cluster.isMaster) {
82+
main();
83+
}

config.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[app]
2+
port=4000
3+
4+
[database]
5+
driver=postgres
6+
7+
[database.connection]
8+
host=localhost
9+
port=5432
10+
user=postgres
11+
password=postgres
12+
database=postgres
13+
14+
[database.options]
15+
test_connection=true
16+
17+
[aws]
18+
aws_access_key_id=AKIAXI6...
19+
aws_secret_access_key=EiBTeA0...
20+
21+
[aws.s3]
22+
bucket=BUCKET_NAME
23+
region=sa-east-1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
exports.up = function(knex) {
3+
return knex.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"');
4+
};
5+
6+
exports.down = function(knex) {
7+
Promise.resolve('ok');
8+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exports.up = function (knex) {
2+
return knex.schema.createTable('project', function (table) {
3+
// Columns
4+
table.uuid('id').unique().primary().notNullable().defaultTo(knex.raw('uuid_generate_v4()'));
5+
table.uuid('ownerId').notNullable();
6+
table.string('name', 60).notNullable();
7+
table.specificType('tags', 'varchar[]').nullable();
8+
table.timestamp('createdAt').notNullable().defaultTo(knex.fn.now());
9+
table.timestamp('deletedAt');
10+
});
11+
};
12+
13+
exports.down = function (knex) {
14+
return knex.schema.dropTable('project');
15+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.up = function (knex) {
2+
return knex.schema.createTable('project_tag', function (table) {
3+
// Columns
4+
table.uuid('id').unique().primary().notNullable().defaultTo(knex.raw('uuid_generate_v4()'));
5+
table.uuid('projectId').notNullable();
6+
table.string('name', 60).notNullable();
7+
table.string('value', 60).notNullable();
8+
});
9+
};
10+
11+
exports.down = function (knex) {
12+
return knex.schema.dropTable('project_tag');
13+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
exports.up = function (knex) {
2+
return knex.schema.createTable('team', function (table) {
3+
// Columns
4+
table.uuid('id').unique().primary().notNullable().defaultTo(knex.raw('uuid_generate_v4()'));
5+
table.uuid('projectId').notNullable();
6+
table.string('name');
7+
table.timestamp('createdAt').notNullable().defaultTo(knex.fn.now());
8+
table.timestamp('deletedAt');
9+
});
10+
};
11+
12+
exports.down = function (knex) {
13+
return knex.schema.dropTable('team');
14+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
exports.up = function (knex) {
2+
return knex.schema.createTable('team_tag', function (table) {
3+
// Columns
4+
table.uuid('id').unique().primary().notNullable().defaultTo(knex.raw('uuid_generate_v4()'));
5+
table.uuid('projectId').notNullable();
6+
table.uuid('teamId').notNullable();
7+
table.string('name', 60).notNullable();
8+
table.string('value', 60).notNullable();
9+
});
10+
};
11+
12+
exports.down = function (knex) {
13+
return knex.schema.dropTable('team_tag');
14+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exports.up = function (knex) {
2+
return knex.schema.createTable('member', function (table) {
3+
// Columns
4+
table.uuid('id').unique().primary().notNullable().defaultTo(knex.raw('uuid_generate_v4()'));
5+
table.uuid('projectId').notNullable();
6+
table.uuid('userId').notNullable();
7+
table.uuid('teamId').notNullable();
8+
table.timestamp('createdAt').notNullable().defaultTo(knex.fn.now());
9+
table.timestamp('deletedAt');
10+
});
11+
};
12+
13+
exports.down = function (knex) {
14+
return knex.schema.dropTable('member');
15+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.up = function (knex) {
2+
return knex.schema.createTable('user_permission', function (table) {
3+
// Columns
4+
table.uuid('id').unique().primary().notNullable().defaultTo(knex.raw('uuid_generate_v4()'));
5+
table.uuid('projectId').notNullable();
6+
table.uuid('userId').notNullable();
7+
table.string('permission', 30).notNullable();
8+
});
9+
};
10+
11+
exports.down = function (knex) {
12+
return knex.schema.dropTable('user_permission');
13+
};

0 commit comments

Comments
 (0)