58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
const Hapi = require('@hapi/hapi');
|
|
require('dotenv').config();
|
|
const { initializeDb } = require('./config/db');
|
|
const { seedUsers } = require('./seed');
|
|
|
|
const init = async () => {
|
|
const origins = [
|
|
...new Set(
|
|
(process.env.FRONTEND_ORIGIN || 'http://localhost:5173')
|
|
.split(',')
|
|
.map((o) => o.trim())
|
|
.filter(Boolean)
|
|
.concat([
|
|
'http://localhost:5173',
|
|
'http://localhost:5174',
|
|
'http://127.0.0.1:5173',
|
|
'http://127.0.0.1:5174',
|
|
])
|
|
),
|
|
];
|
|
|
|
const server = Hapi.server({
|
|
port: Number(process.env.PORT || 3050),
|
|
host: process.env.HOST || '0.0.0.0',
|
|
routes: {
|
|
cors: {
|
|
origin: origins,
|
|
headers: ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'],
|
|
additionalHeaders: ['X-Requested-With'],
|
|
},
|
|
},
|
|
});
|
|
|
|
server.route([
|
|
{
|
|
method: 'GET',
|
|
path: '/health',
|
|
handler: () => ({ status: 'ok', service: 'tgics' }),
|
|
},
|
|
...require('./routes/authRoutes'),
|
|
...require('./routes/dashboardRoutes'),
|
|
...require('./routes/doctorRoutes'),
|
|
...require('./routes/surveyRoutes'),
|
|
]);
|
|
|
|
await initializeDb();
|
|
await seedUsers();
|
|
await server.start();
|
|
console.log('TGICS API running on %s', server.info.uri);
|
|
};
|
|
|
|
process.on('unhandledRejection', (err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|
|
|
|
init();
|