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 * as api from './server/api';
|
||||
import * as shortener from './server/shortener';
|
||||
import * as contentDelivery from './server/contentDelivery';
|
||||
import {Sequelize} from 'sequelize';
|
||||
|
||||
// Load & check environment
|
||||
require('dotenv').config();
|
||||
require('./util/envCheck').validate();
|
||||
|
||||
// Connect to database
|
||||
mongoose.connect(process.env.MONGOOSE_STRING || '', (e: CallbackError) => {
|
||||
if (e) throw new Error(`Could not connect to database: ${e.message}`);
|
||||
console.log("[DB] Successfully connected to the database");
|
||||
export const sequelize = new Sequelize(process.env.DB_NAME || '', process.env.DB_USER || '', process.env.DB_PASS || '', {host: process.env.DB_HOST || '', dialect: 'mariadb'});
|
||||
|
||||
sequelize.authenticate().then(() => {
|
||||
console.log('[DB] Connected to database');
|
||||
start();
|
||||
});
|
||||
}).catch(err => console.error(err));
|
||||
|
||||
// Start all servers
|
||||
const start = () => {
|
||||
api.startServer(parseInt(process.env.API_PORT || ''));
|
||||
shortener.startServer(parseInt(process.env.SHORTENER_PORT || ''));
|
||||
const start = async () => {
|
||||
(await import("./server/api")).startServer(parseInt(process.env.API_PORT || ''));
|
||||
(await import("./server/shortener")).startServer(parseInt(process.env.SHORTENER_PORT || ''));
|
||||
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