-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (32 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Imports:
import express from 'express';
import favicon from 'express-favicon';
import api from './src/api/index.js';
import commonErrors from './src/messages/error/http.js';
import cors from 'cors';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import morgan from 'morgan';
import cookieParser from 'cookie-parser';
// Declarations and app configuration:
const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-line no-use-before-define
const { notFound } = commonErrors;
const frontendOrigin = process.env.FRONTEND_URL
const secret = process.env.JWT_SECRET;
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser(secret));
app.use(cors({origin: frontendOrigin, credentials:true}));
app.use(express.static('public'));
app.use(morgan('combined'));
app.use(favicon(__dirname + '/public/favicon-32x32.png'));
app.set('json spaces', 2);
// Main routing
app.use(api);
app.use('/api', api);
app.use('/api/v1', api);
// Not found handler:
app.use((req, res, next) => res.status(404).json(notFound()));
// Start server:
app.listen(process.env.PORT || 3000);