52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
const express = require("express");
|
|
const bodyParser = require("body-parser");
|
|
const path = require("path");
|
|
const morgan = require("morgan");
|
|
const dbConnection = require("./models/dbConnection");
|
|
const fs = require("fs");
|
|
const httpolyglot = require("httpolyglot");
|
|
|
|
// credentials
|
|
const config = require("./config.json");
|
|
const port = config.port;
|
|
|
|
// Router
|
|
const search = require("./routes/search");
|
|
const regions = require("./routes/regions");
|
|
|
|
const app = express();
|
|
|
|
(async () => {
|
|
try {
|
|
// console.log(process.env);
|
|
const dbConn = await dbConnection(config);
|
|
|
|
// Express middleware
|
|
app.use(morgan("dev"));
|
|
app.use(express.static(path.join(__dirname, "../../dist")));
|
|
app.use(bodyParser.json());
|
|
|
|
// Express routes
|
|
app.use(search(dbConn));
|
|
app.use(regions(dbConn));
|
|
|
|
app.use((err, req, res, next) => {
|
|
// 500
|
|
if (true) {
|
|
next();
|
|
} else {
|
|
res.status(500).send();
|
|
}
|
|
});
|
|
|
|
// Start webserver
|
|
app.listen(port, () => {
|
|
console.log(`Travopti backend listening at http://localhost:${port}`)
|
|
});
|
|
} catch (error) {
|
|
// TODO: logging
|
|
console.error("Failed to start the webserver");
|
|
console.error(error);
|
|
}
|
|
})();
|