-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (24 loc) · 943 Bytes
/
server.js
File metadata and controls
32 lines (24 loc) · 943 Bytes
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
import express from 'express'
import models from './models'
import rp from 'request-promise'
import cors from 'cors'
import bodyParser from 'body-parser'
import * as FilmsController from './controllers/films'
import * as PeopleController from './controllers/people'
import { fetchFilms, fetchPeople } from './scripts/importFromSwapi'
const app = express();
const port = process.env.PORT || 3001;
app.use(bodyParser());
app.get('/films', cors(), FilmsController.getAll);
app.post('/films', cors(), FilmsController.createOne);
app.put('/film/:id', cors(), FilmsController.updateOne);
app.delete('/film/:id', cors(), FilmsController.deleteOne);
app.get('/people', cors(), PeopleController.getAll);
models.sequelize.sync({force: true})
.then(() => {
fetchFilms();
fetchPeople();
app.listen(port, console.log(`Magic happens on PORT ${port}`));
app.on('error', (err) => console.error(err.stack));
});
export default app