2020-09-14 11:03:06 +02:00
|
|
|
require('dotenv').config();
|
2020-07-22 07:36:06 +02:00
|
|
|
const express = require('express');
|
|
|
|
const mongo = require('mongodb');
|
|
|
|
const mongoose = require('mongoose');
|
|
|
|
const cors = require('cors');
|
|
|
|
const app = express();
|
2017-02-18 19:57:45 +01:00
|
|
|
|
2020-07-22 07:36:06 +02:00
|
|
|
// Basic Configuration
|
|
|
|
const port = process.env.PORT || 3000;
|
2017-02-18 19:57:45 +01:00
|
|
|
|
2020-07-22 07:36:06 +02:00
|
|
|
/* This project needs a database */
|
2019-10-28 07:09:03 +01:00
|
|
|
// mongoose.connect(process.env.DB_URI);
|
2017-02-18 19:57:45 +01:00
|
|
|
|
|
|
|
app.use(cors());
|
|
|
|
|
2020-07-22 07:36:06 +02:00
|
|
|
/* This project needs to parse POST bodies */
|
|
|
|
// You should mount body-parser here
|
2017-02-18 19:57:45 +01:00
|
|
|
|
|
|
|
app.use('/public', express.static(process.cwd() + '/public'));
|
|
|
|
|
2020-07-22 07:36:06 +02:00
|
|
|
app.get('/', function(req, res) {
|
2017-02-18 19:57:45 +01:00
|
|
|
res.sendFile(process.cwd() + '/views/index.html');
|
|
|
|
});
|
|
|
|
|
2020-07-22 07:36:06 +02:00
|
|
|
// Your first API endpoint
|
|
|
|
app.get('/api/hello', function(req, res) {
|
|
|
|
res.json({ greeting: 'hello API' });
|
2017-02-18 19:57:45 +01:00
|
|
|
});
|
|
|
|
|
2020-07-22 07:36:06 +02:00
|
|
|
app.listen(port, function() {
|
|
|
|
console.log(`Listening on port ${port}`);
|
|
|
|
});
|