-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (32 loc) · 1.06 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
const express = require('express');
const app = express();
const http = require('http').Server(app);
const cors = require('cors');
const path = require('path');
const axios = require('axios');
require('dotenv').config({ path: path.join(__dirname, '/.env') });
const PORT = process.env.PORT;
const INDEX_PATH = './index.html';
app.use(cors());
app.use((req, res, next) => {
console.log(`--> ${req.method} ${req.path}`);
next();
});
app.use(express.static(path.join(__dirname, '/../_site')));
app.get('/api/apod', (req, res)=>{
console.log('Fetching NASA API');
// &date=2022-02-16 for date based content
axios.get('https://api.nasa.gov/planetary/apod?api_key=Se2v4vDZIfaUh1R8CeO4940NxTKNbjQxzPVhst96')
.then(response => {
console.log('response.data', response.data);
res.json(response.data)
})
.catch((error) => console.log(error));
});
app.get(['/*'], (req, res) => {
console.log('Index file loading');
res.sendFile(path.join(__dirname));
});
http.listen(PORT, () => {
console.log(`listening on PORT ${PORT}, ${process.env.NODE_ENV} ENVIRONMENT.`);
});