-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.js
50 lines (38 loc) · 1.18 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
const axios = require('axios');
const express = require('express');
const app = express();
const expressip = require('express-ip');
const PORT = process.env.PORT || 5000;
const path = require('path');
const handlebars = require('express-handlebars');
app.engine('.hbs', handlebars({ extname: '.hbs' }));
app.set("PORT", PORT);
app.use(expressip().getIpInfoMiddleware);
app.use(express.static(path.join(__dirname, 'assets')));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '.hbs');
app.get('/', function (req, res) {
res.render("index", {title:"Jobby"});
});
app.get('/search', function (req, res) {
queries = req.query;
let url = `https://indreed.herokuapp.com/api/jobs`;
if (queries){
axios.get(url, {
params: queries
})
.then(function(response){
res.render("search", { title: "Jobby", jobs: response.data});
})
.catch(function(error) {
console.log(error);
});
}
else {
res.render("search", {title: "Jobby"})
}
});
app.listen(app.get('PORT'), function () {
console.log('Express started on http://localhost:' +
app.get('PORT') + '; press Ctrl-C to terminate.');
});