|
|
|
@ -1,8 +1,10 @@ |
|
|
|
import chalk from 'chalk'; |
|
|
|
import Fastify from 'fastify' |
|
|
|
import formBodyPlugin from 'fastify-formbody'; |
|
|
|
import fastifyMultipart from 'fastify-multipart'; |
|
|
|
import Sequelize from 'sequelize'; |
|
|
|
import { DatabaseConfig } from './config/database.config.js'; |
|
|
|
import { ServerConfig } from './config/server.config.js'; |
|
|
|
import UserEntity from './model/user.model.js'; |
|
|
|
import AuthController from './route/auth.controller.js'; |
|
|
|
import UserController from './route/user.controller.js'; |
|
|
|
@ -15,7 +17,7 @@ async function Database(){ |
|
|
|
const opts = {db}; |
|
|
|
UserEntity(opts); |
|
|
|
} |
|
|
|
await db.authenticate(); //connect to the database of choice
|
|
|
|
await db.authenticate(); //connect to your database of choice
|
|
|
|
await db.sync({alter: true}); //add missing tables and columns
|
|
|
|
} |
|
|
|
|
|
|
|
@ -28,17 +30,22 @@ async function WebApp(){ |
|
|
|
UserController(opts); |
|
|
|
} |
|
|
|
app.get('/', () => 'Hello. D:'); |
|
|
|
const options = { port: 3000, host: '127.0.0.1' }; |
|
|
|
const address = await app.listen(options); |
|
|
|
return `Server is listening on ${address}.`; |
|
|
|
const address = await app.listen(ServerConfig); |
|
|
|
return chalk.magenta(`Server is listening on ${address}.`); |
|
|
|
} |
|
|
|
|
|
|
|
(async () => { |
|
|
|
//initialize
|
|
|
|
const step = async (func, name) => { |
|
|
|
const start = Date.now(); |
|
|
|
const tag = chalk.yellow(name); |
|
|
|
try{ |
|
|
|
const msg = await func(); |
|
|
|
console.log(`[${name}] (${(Date.now() - start)} ms) ${msg || 'Done.'}`); |
|
|
|
console.log(`[${tag}] (${(Date.now() - start)} ms) ${msg || chalk.green('Done.')}`); |
|
|
|
}catch(err){ |
|
|
|
console.log(`[${tag}] ${chalk.red('Failure.')}`); |
|
|
|
throw err; |
|
|
|
} |
|
|
|
}; |
|
|
|
await step(Database, 'DB'); |
|
|
|
await step(WebApp, 'Fastify'); |
|
|
|
|