{"size": 824, "ext": "js", "max_stars_repo_path": "services/src/server.js", "max_stars_repo_name": "Orekhov/FrequencyDictionaryLearning", "max_stars_repo_stars_event_min_datetime": "2019-10-28T07:38:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-27T15:48:32.000Z", "max_issues_repo_path": "services/src/server.js", "max_issues_repo_name": "Orekhov/FrequencyDictionaryLearning", "max_issues_repo_issues_event_min_datetime": "2020-04-06T19:29:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-05T06:17:07.000Z", "max_forks_repo_path": "services/src/server.js", "max_forks_repo_name": "Orekhov/FrequencyDictionaryLearning", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 14, "max_forks_count": null, "avg_line_length": 32.96, "max_line_length": 88, "alphanum_fraction": 0.6674757282}
const express = require('express');
const path = require('path');
const router = require('./router');
const auth = require('./auth');

function startServer() {
    const apiBasePath = '/api';
    const server = express();
    server.use(apiBasePath, express.json({limit:'256kb'})); // TODO: make route specific
    server.use(apiBasePath, auth.authenticate);
    server.use(apiBasePath, router);

    const staticFilesPath = path.join(__dirname, '../fdl-web');
    const indexHtmlPath = path.join(staticFilesPath, 'index.html');

    server.use('/', express.static(staticFilesPath));
    server.get('*', (req, res, next) => res.sendFile(indexHtmlPath));

    const port = process.env.PORT || 8080;
    server.listen(port, () => console.log(`listening on port ${port}`));
}

module.exports = {
    startServer: startServer
};