Migrated the app.ts
This commit is contained in:
parent
0482997ec1
commit
61d766e26b
23
app.ts
23
app.ts
@ -1,23 +1,22 @@
|
|||||||
import mongoose, {CallbackError} from 'mongoose';
|
import {Sequelize} from 'sequelize';
|
||||||
import * as api from './server/api';
|
|
||||||
import * as shortener from './server/shortener';
|
|
||||||
import * as contentDelivery from './server/contentDelivery';
|
|
||||||
|
|
||||||
// Load & check environment
|
// Load & check environment
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
require('./util/envCheck').validate();
|
require('./util/envCheck').validate();
|
||||||
|
|
||||||
// Connect to database
|
// Connect to database
|
||||||
mongoose.connect(process.env.MONGOOSE_STRING || '', (e: CallbackError) => {
|
export const sequelize = new Sequelize(process.env.DB_NAME || '', process.env.DB_USER || '', process.env.DB_PASS || '', {host: process.env.DB_HOST || '', dialect: 'mariadb'});
|
||||||
if (e) throw new Error(`Could not connect to database: ${e.message}`);
|
|
||||||
console.log("[DB] Successfully connected to the database");
|
sequelize.authenticate().then(() => {
|
||||||
|
console.log('[DB] Connected to database');
|
||||||
start();
|
start();
|
||||||
});
|
}).catch(err => console.error(err));
|
||||||
|
|
||||||
// Start all servers
|
// Start all servers
|
||||||
const start = () => {
|
const start = async () => {
|
||||||
api.startServer(parseInt(process.env.API_PORT || ''));
|
(await import("./server/api")).startServer(parseInt(process.env.API_PORT || ''));
|
||||||
shortener.startServer(parseInt(process.env.SHORTENER_PORT || ''));
|
(await import("./server/shortener")).startServer(parseInt(process.env.SHORTENER_PORT || ''));
|
||||||
if (!process.env.DISABLE_CONTENT_DELIVERY)
|
if (!process.env.DISABLE_CONTENT_DELIVERY)
|
||||||
contentDelivery.startServer(parseInt(process.env.CDN_PORT || ''));
|
(await import("./server/contentDelivery")).startServer(parseInt(process.env.CDN_PORT || ''));
|
||||||
|
sequelize.sync();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user