44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
|
|
import express from 'express';
|
||
|
|
import session from 'express-session';
|
||
|
|
import path from 'path';
|
||
|
|
import { JsonSessionStore } from './sessionStore';
|
||
|
|
import authRouter from './routes/auth';
|
||
|
|
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';
|
||
|
|
import { generateLocales } from './localeGenerator';
|
||
|
|
|
||
|
|
generateLocales();
|
||
|
|
|
||
|
|
const app = express();
|
||
|
|
|
||
|
|
app.use( express.json() );
|
||
|
|
app.use( express.text( { type: 'text/plain' } ) );
|
||
|
|
app.use( session(
|
||
|
|
{
|
||
|
|
store: new JsonSessionStore( path.join( __dirname, '..', 'storage', 'sessions' ) ),
|
||
|
|
secret: 'roject-secret-key',
|
||
|
|
resave: false,
|
||
|
|
saveUninitialized: false,
|
||
|
|
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 }
|
||
|
|
} ) );
|
||
|
|
|
||
|
|
app.use( express.static( path.join( __dirname, '..', 'public' ) ) );
|
||
|
|
|
||
|
|
app.use( '/api/auth', authRouter );
|
||
|
|
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 );
|
||
|
|
|
||
|
|
app.get( '/', ( req, res ) =>
|
||
|
|
{
|
||
|
|
res.redirect( req.session.userId ? '/dashboard.html' : '/login.html' );
|
||
|
|
} );
|
||
|
|
|
||
|
|
const PORT = process.env.PORT ? Number( process.env.PORT ) : 3000;
|
||
|
|
app.listen( PORT, () => console.log( `Roject running on http://localhost:${PORT}` ) );
|