updates dependencies and devDependencies to latest
[urlittler] / server.js
1 /* eslint-disable capitalized-comments */
2 'use strict';
3
4 const http = require('http');
5
6 const DB = require('./src/db');
7 const Logger = require('./src/logger');
8 const Service = require('./src/service');
9 const { fileScope } = require('./src/common');
10 const { version } = require('./package.json');
11
12 const _fileScope = fileScope(__filename)('main');
13
14 const PORT = process.env.PORT || 3001;
15 const ADDR = process.env.LISTEN_ADDR || '127.0.0.1';
16
17 const logger = new Logger({
18 // ignoreBelowLevel: 'info',
19 });
20 const db = new DB(logger, {
21 connectionString: 'postgresql://%2Fhome%2Ffek%2Fprojects%2Fhubl%2Fnodejs%2Fpostgres_dev-13/urlittler',
22 // connectionString: 'sqlite://',
23 });
24 const service = new Service(logger, db, {
25 proxyPrefix: process.env.PROXY_PREFIX || '', // '/lil',
26 manager: {
27 selfBaseUrl: process.env.BASE_URL || '',
28 },
29 });
30
31 http.createServer((req, res) => {
32 service.dispatch(req, res);
33 }).listen(PORT, ADDR, (err) => {
34 if (err) {
35 logger.error(_fileScope, 'error starting server:', err);
36 throw err;
37 }
38 logger.info(_fileScope, `server (version ${version}) started on ${ADDR}:${PORT}`);
39 });