forked from konrad-glowacki/express-simple-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
47 lines (41 loc) · 1000 Bytes
/
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
41
42
43
44
45
46
47
const axios = require('axios');
const express = require('express');
const server = express();
const PORT = process.env.PORT || 3300;
server.use(express.static('public'));
server.get('/', (_req, res) => {
res.send('Hello Express!');
});
server.get('/fetch-wordpress-graphql', async (_req, res) => {
const query = `
query QueryPosts {
posts {
nodes {
id
content
title
slug
featuredImage {
node {
mediaDetails {
sizes {
sourceUrl
name
}
}
}
}
}
}
}
`;
const response = await axios.post(process.env.GRAPHQL_API_URL, { query });
res.send(response.data.data.posts.nodes);
});
server.get('/envs', (req, res) => {
console.log(process.env);
res.send('Envs displayed in logs!');
});
server.listen(PORT, () => {
console.log(`Application is listening at port ${PORT}`);
});