35 lines
978 B
TypeScript
35 lines
978 B
TypeScript
// Load dotenv before any process.env is accessed
|
|
import dotenv from 'dotenv';
|
|
dotenv.config()
|
|
|
|
import express from 'express';
|
|
import morgan from 'morgan';
|
|
import path from 'path';
|
|
import bodyParser from 'body-parser';
|
|
import routes from './routes';
|
|
|
|
const app = express();
|
|
|
|
const port = process.env.PORT ?? 3000;
|
|
|
|
const log_format = (process.env.NODE_ENV === "dev") ? "dev": "combined";
|
|
console.log("=== LOG CONFIG ===");
|
|
console.log(`log format: ${log_format}`);
|
|
console.log("=== END LOG CONFIG ===");
|
|
|
|
// Need the path.join for node to resolve correctly the templates directory
|
|
app.set('views', path.join(__dirname, 'templates'));
|
|
app.set('view engine', 'ejs');
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
app.use(bodyParser.json({ limit: '50mb', type: 'application/*+json' }));
|
|
|
|
// Add logs
|
|
app.use(morgan(log_format));
|
|
|
|
// Defines endpoints
|
|
app.use(routes);
|
|
|
|
app.listen(port, () => {
|
|
return console.log(`Briques is listening at http://localhost:${port}`);
|
|
});
|