-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
23 lines (18 loc) · 725 Bytes
/
app.js
File metadata and controls
23 lines (18 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import express, { json } from 'express';
import { createMovieRouter } from './routes/movies.js';
import { corsMiddleware } from './middlewares/cors.js';
import swaggerUi from 'swagger-ui-express';
import fs from 'fs';
const swaggerDocument = JSON.parse(fs.readFileSync('./openApiDocs.json', 'utf8'));
export const createApp = ({ movieModel }) => {
const app = express();
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.disable('x-powered-by');
app.use(json());
app.use(corsMiddleware());
app.use('/movies', createMovieRouter({ movieModel }));
const PORT = process.env.PORT ?? 1234;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
};