generated from NewcastleRSE/Standard-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (28 loc) · 894 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
require('dotenv').config()
const express = require('express');
const db = require('./connect')
const app = express()
const path = require('path');
const cors = require('cors');
const bodyParser = require('body-parser');
const corsOptions = {
origin: process.env.REFERRER_URL
};
app.use(cors(corsOptions));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const PORT = process.env.DB_PORT || 3000;
const connection = db.connectToDB
// Allow app to server static files from the public directory
app.use(express.static(path.join(__dirname, 'public')));
/* GET home page. */
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
});
// api function
app.get('/api/bpi_cat', db.getBpiCat);
app.listen(PORT, function (err) {
if (err) console.log(err);
console.log("BPI listening");
});
module.exports = app;