-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAPIserver.js
More file actions
executable file
·30 lines (25 loc) · 1.01 KB
/
APIserver.js
File metadata and controls
executable file
·30 lines (25 loc) · 1.01 KB
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
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const PORT = process.env.PORT || 3001;
const cors = require('cors');
const axios = require('axios')
const APIkeys = require('./APIkeys') //export of APIkeys, could not reuse the keys in src because ES5 doesnt play nice with ES7 and ES8
// Configure body parser for AJAX requests
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Serve up static assets
app.use(express.static("client/build"));
app.use(cors());
app.get('/magic', (req,res,next) => {
var magicSeaweedURL = encodeURI("http://magicseaweed.com/api/"+APIkeys.magicSeaweedKey+"/forecast/?spot_id="+APIkeys.magicSeaweedSpotID);
axios.get(magicSeaweedURL).then(results =>{
res.json(results.data)
}).catch( err => {
if (err) res.json(err)
})
});
// Start the API server
app.listen(PORT, function() {
console.log(`🌎 ==> API Server now listening on PORT ${PORT}!`);
});