-
Notifications
You must be signed in to change notification settings - Fork 32
/
server.js
38 lines (28 loc) · 1.22 KB
/
server.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
// backend - server.js - Routes API requests from the frontend to Kintone
// Express Server Setup
const express = require('express');
const cors = require('cors');
const PORT = 50000;
const app = express();
// Hide sensitive info in a .env file with dotenv
require('dotenv').config({ path: '../.env' });
// Get Kintone credentials from a .env file
const subdomain = process.env.SUBDOMAIN;
const appID = process.env.APPID;
const apiToken = process.env.APITOKEN;
// Parse incoming requests with JSON payloads
app.use(express.json());
// Set Cross-Origin Resource Sharing (CORS) to frontend React App
app.use(cors());
const corsOptions = {
origin: 'http://localhost:3000'
};
// Kintone's record(s) endpoints
const multipleRecordsEndpoint = `https://${subdomain}.kintone.com/k/v1/records.json?app=${appID}`
const singleRecordEndpoint = `https://${subdomain}.kintone.com/k/v1/record.json?app=${appID}`;
// Kintone app's field codes are 'country' 'state' and 'city'.
// TODO: Create a GET endpoint at /getData
// TODO: Create a POST endpoint at /postData
app.listen(PORT, () => {
console.log(`\n Backend server listening at http://localhost:${PORT} \n Confirm if Kintone records are being retrieved at \n http://localhost:${PORT}/getData`);
});