UNPKG

2.15 kBJavaScriptView Raw
1'use strict';
2
3const express = require('express'),
4 env = require('./core/env'),
5 bodyParser = require('body-parser'),
6 morgan = require('morgan'),
7 tableStorageManager = require('./core/table/TableStorageManager'),
8 cli = require('./core/cli');
9
10class AzuriteTable {
11 constructor() {
12 this.server;
13 // Support for PM2 Graceful Shutdown on Windows and Linux/OSX
14 // See http://pm2.keymetrics.io/docs/usage/signals-clean-restart/
15 if (process.platform === 'win32') {
16 process.on('message', function (msg) {
17 if (msg == 'shutdown') {
18 this.close();
19 }
20 });
21 }
22 else {
23 process.on('SIGINT', function () {
24 this.close();
25 });
26 }
27 }
28
29 init(options) {
30 return env.init(options)
31 .then(() => {
32 return tableStorageManager.init()
33 })
34 .then(() => {
35 const app = express();
36 if (!env.silent) {
37 app.use(morgan('dev'));
38 }
39 app.use(bodyParser.raw({
40 inflate: true,
41 // According to https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-the-table-service-data-model
42 // maximum size of an entity is 1MB
43 limit: '10000kb',
44 type: function (type) {
45 return true;
46 }
47 }));
48 require('./routes/table/TableRoute')(app);
49 require('./routes/table/EntityRoute')(app);
50 app.use(require('./middleware/table/validation'));
51 app.use(require('./middleware/table/actions'));
52 this.server = app.listen(env.tableStoragePort, () => {
53 if (!env.silent) {
54 cli.tableStorageStatus();
55 }
56 });
57 });
58 }
59
60 close() {
61 return BbPromise.try(() => {
62 this.server.close();
63 });
64 }
65}
66
67module.exports = AzuriteTable;
\No newline at end of file