-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (24 loc) · 759 Bytes
/
server.js
File metadata and controls
30 lines (24 loc) · 759 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
"use strict";
const express = require('express')
const app = express()
const port = process.env.PORT || 3001;
const character_model = require('./data');
app.use(express.json())
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Access-Control-Allow-Headers');
next();
});
app.get('/', (req, res) => {
character_model.getCharacters()
.then(response => {
res.status(200).send(response);
})
.catch(error => {
res.status(500).send(error);
})
});
app.listen(port, () => {
console.log(`App running on port ${port}.`)
});