-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·55 lines (42 loc) · 1.33 KB
/
app.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
48
49
50
51
52
53
54
55
import path from 'path';
import compression from 'compression';
import express from 'express';
import logger from 'morgan';
import cors from 'cors';
import bodyParser from 'body-parser';
import {} from 'dotenv/config';
const app = express();
app.use(compression());
// routes
const contentful = require('./server/routes/contentful');
const upload = require('./server/routes/upload');
const sendEmail = require('./server/emails/sendEmail');
// Set port
app.set('port', (process.env.PORT || 3000));
// Setting up basic middleware for all Express requests
app.use(logger('dev')); // Log requests to API using morgan
// create application/x-www-form-urlencoded parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true,
}));
// cors
app.use(cors({
origin: true,
}));
app.use(express.static(path.join(__dirname, 'public')));
// Contentful route
app.get('/getAllContent', contentful.getAllContent);
// Send email route
app.post('/sendEmail', sendEmail.default);
// Upload route
app.use('/upload', upload.default);
// Catch all other paths and serve the index file
app.all('*', function(request, response) {
response.sendFile(path.join(__dirname, 'public/index.html'));
});
// Listen to port
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
module.exports = app;