Updated the server.ts
This commit is contained in:
parent
6faf3a8437
commit
9cf2192578
@ -1,5 +1,6 @@
|
|||||||
import express, {Application} from 'express';
|
import express, {Application} from 'express';
|
||||||
import mongoose, {CallbackError} from "mongoose";
|
import mongoose, {CallbackError} from "mongoose";
|
||||||
|
import v1Router from "./routes/v1";
|
||||||
|
|
||||||
const MONGOOSE_STRING = process.env.MONGOOSE_STRING || 'mongodb://localhost:27017';
|
const MONGOOSE_STRING = process.env.MONGOOSE_STRING || 'mongodb://localhost:27017';
|
||||||
|
|
||||||
@ -7,12 +8,25 @@ const app: Application = express();
|
|||||||
const port: number = parseInt(process.env.SERVER_PORT || '8025');
|
const port: number = parseInt(process.env.SERVER_PORT || '8025');
|
||||||
const isDevelopment: boolean = process.env.NODE_ENV !== 'production';
|
const isDevelopment: boolean = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
|
// Configure backend
|
||||||
|
app.disable("x-powered-by");
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
// Configure routers
|
||||||
|
app.use("/", v1Router); // <- Newest
|
||||||
|
|
||||||
|
app.use("/v1/", v1Router);
|
||||||
|
|
||||||
|
// Configure mongoose
|
||||||
mongoose.set("strictQuery", false);
|
mongoose.set("strictQuery", false);
|
||||||
|
|
||||||
|
// Connect to database
|
||||||
mongoose.connect(MONGOOSE_STRING, (error: CallbackError) => {
|
mongoose.connect(MONGOOSE_STRING, (error: CallbackError) => {
|
||||||
if (error) throw new Error(`Could not connect to database: ${error.message}`);
|
if (error) throw new Error(`Could not connect to database: ${error.message}`);
|
||||||
console.log(`Successfully connected to the database @${MONGOOSE_STRING.split("://")[1].split("/")[0]}`);
|
console.log(`Successfully connected to the database @${MONGOOSE_STRING.split("://")[1].split("/")[0]}`);
|
||||||
run();
|
run();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Start the backend
|
||||||
const run = () =>
|
const run = () =>
|
||||||
app.listen(port, () => console.log(`LicenseAPI ${isDevelopment ? "development" : "production"} server started under port ${port}`));
|
app.listen(port, () => console.log(`LicenseAPI ${isDevelopment ? "development" : "production"} server started under port ${port}`));
|
Loading…
x
Reference in New Issue
Block a user