2017-02-18 19:57:45 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-10-29 22:16:41 +01:00
|
|
|
const express = require('express'),
|
|
|
|
mongo = require('mongodb'),
|
|
|
|
mongoose = require('mongoose'),
|
|
|
|
cors = require('cors'),
|
|
|
|
app = express();
|
2017-02-18 19:57:45 +01:00
|
|
|
|
|
|
|
// Basic Configuration
|
2018-10-29 22:16:41 +01:00
|
|
|
const port = process.env.PORT || 3000;
|
2017-02-18 19:57:45 +01:00
|
|
|
|
|
|
|
/** this project needs a db !! **/
|
|
|
|
// mongoose.connect(process.env.MONGOLAB_URI);
|
|
|
|
|
|
|
|
app.use(cors());
|
|
|
|
|
|
|
|
/** this project needs to parse POST bodies **/
|
|
|
|
// you should mount the body-parser here
|
|
|
|
|
2018-10-29 22:16:41 +01:00
|
|
|
app.use('/public', express.static(`${process.cwd()}/public`));
|
2017-02-18 19:57:45 +01:00
|
|
|
|
2018-10-29 22:16:41 +01:00
|
|
|
app.get('/', (req, res) => {
|
|
|
|
res.sendFile(`${process.cwd()}/views/index.html`);
|
2017-02-18 19:57:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// your first API endpoint...
|
2018-10-29 22:16:41 +01:00
|
|
|
app.get("/api/hello", (req, res) => {
|
2017-02-18 19:57:45 +01:00
|
|
|
res.json({greeting: 'hello API'});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-10-29 22:16:41 +01:00
|
|
|
app.listen(port, () => {
|
2017-02-18 19:57:45 +01:00
|
|
|
console.log('Node.js listening ...');
|
2018-10-29 22:16:41 +01:00
|
|
|
});
|