2026-07-06 17:28:59 +00:00
|
|
|
import express from 'express';
|
2026-07-13 12:45:06 +00:00
|
|
|
import cookieParser from 'cookie-parser';
|
2026-07-06 17:28:59 +00:00
|
|
|
import path from 'path';
|
2026-07-14 11:31:11 +00:00
|
|
|
import { ROOT } from './rootDir';
|
2026-07-13 12:45:06 +00:00
|
|
|
import { jwtMiddleware, requireAuth } from './middleware/auth';
|
2026-07-06 17:28:59 +00:00
|
|
|
import groupsRouter from './routes/groups';
|
|
|
|
|
import projectsRouter from './routes/projects';
|
|
|
|
|
import filesRouter from './routes/files';
|
|
|
|
|
import localesRouter from './routes/locales';
|
|
|
|
|
import layoutRouter from './routes/layout';
|
2026-07-10 18:18:15 +00:00
|
|
|
import rojosRouter from './routes/rojos';
|
2026-07-06 17:28:59 +00:00
|
|
|
import { generateLocales } from './localeGenerator';
|
2026-07-13 19:42:21 +00:00
|
|
|
import deployRouter from './routes/deploy';
|
2026-07-14 13:45:27 +00:00
|
|
|
import { EmailService } from './email/EmailService';
|
2026-07-06 17:28:59 +00:00
|
|
|
|
|
|
|
|
generateLocales();
|
|
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
|
2026-07-13 19:42:21 +00:00
|
|
|
app.use( '/api/deploy', deployRouter );
|
2026-07-06 17:28:59 +00:00
|
|
|
app.use( express.json() );
|
|
|
|
|
app.use( express.text( { type: 'text/plain' } ) );
|
2026-07-13 12:45:06 +00:00
|
|
|
app.use( cookieParser() );
|
|
|
|
|
app.use( jwtMiddleware );
|
2026-07-06 17:28:59 +00:00
|
|
|
|
2026-07-14 11:31:11 +00:00
|
|
|
app.use( express.static( path.join( ROOT, 'build', 'app' ) ) );
|
2026-07-06 17:28:59 +00:00
|
|
|
|
|
|
|
|
app.use( '/api/groups', groupsRouter );
|
|
|
|
|
app.use( '/api/projects', projectsRouter );
|
|
|
|
|
app.use( '/api/files', filesRouter );
|
|
|
|
|
app.use( '/api/locales', localesRouter );
|
|
|
|
|
app.use( '/api/layout', layoutRouter );
|
2026-07-10 18:18:15 +00:00
|
|
|
app.use( '/api/rojos', rojosRouter );
|
2026-07-06 17:28:59 +00:00
|
|
|
|
2026-07-13 12:45:06 +00:00
|
|
|
app.get( '/api/auth/me', requireAuth, ( req, res ) => res.json( req.user ) );
|
|
|
|
|
|
|
|
|
|
app.get( '/', ( _req, res ) => res.redirect( '/dashboard.html' ) );
|
2026-07-06 17:28:59 +00:00
|
|
|
|
2026-07-14 11:31:11 +00:00
|
|
|
export function startServer( port: number ): void {
|
2026-07-14 13:45:27 +00:00
|
|
|
app.listen( port, () =>
|
|
|
|
|
{
|
|
|
|
|
const time = new Date().toISOString();
|
|
|
|
|
console.log( `Roject running on http://localhost:${port}` );
|
|
|
|
|
EmailService.sendEmail(
|
|
|
|
|
EmailService.reportEmail,
|
|
|
|
|
'Roject — server started',
|
|
|
|
|
`Server started at ${time} on port ${port}.`
|
|
|
|
|
).catch( () => {} );
|
|
|
|
|
} );
|
2026-07-14 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( require.main === module ) {
|
|
|
|
|
const PORT = process.env.PORT ? Number( process.env.PORT ) : 3000;
|
|
|
|
|
startServer( PORT );
|
|
|
|
|
}
|