Skip to content

Commit

Permalink
fix: switching to port 5555 for macOS development
Browse files Browse the repository at this point in the history
Working around sveltejs/template#184
  • Loading branch information
tjvantoll committed May 25, 2022
1 parent 7d4ab44 commit c83fd88
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 62 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public -s",
"start": "sirv public --single --port 5555",
"test": "jest",
"test:watch": "npm run test -- --watch"
},
Expand Down
127 changes: 66 additions & 61 deletions server/server.js
@@ -1,108 +1,113 @@
'use strict';
const Hapi = require('@hapi/hapi');
const axios = require('axios');
"use strict";
const Hapi = require("@hapi/hapi");
const axios = require("axios");

const server = Hapi.server({
port: 3000,
host: '0.0.0.0', // needed for Render deployment
host: "0.0.0.0", // needed for Render deployment
});

const buildBody = (device_uid, to, from) => {
return {
"size": 500,
"sort": [
size: 500,
sort: [
{
"when_captured": {
"order": "desc"
}
}
when_captured: {
order: "desc",
},
},
],
"query": {
"bool": {
"must": [],
"filter": [
query: {
bool: {
must: [],
filter: [
{
"bool": {
"should": [
bool: {
should: [
{
"match_phrase": {
"device_urn": "note:" + device_uid
}
}
]
}
match_phrase: {
device_urn: "note:" + device_uid,
},
},
],
},
},
{
"range": {
"service_uploaded": {
"format": "strict_date_optional_time",
"gte": from,
"lte": to
}
}
}
]
}
}
range: {
service_uploaded: {
format: "strict_date_optional_time",
gte: from,
lte: to,
},
},
},
],
},
},
};
}
};

const url = 'https://40ad140d461d810ac41ed710b5c7a5b6.us-west-2.aws.found.io:9243/_search';
const url =
"https://40ad140d461d810ac41ed710b5c7a5b6.us-west-2.aws.found.io:9243/_search";
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + new Buffer(process.env.SAFECAST_USERNAME + ':' + process.env.SAFECAST_PASSWORD).toString('base64')
"Content-Type": "application/json",
Authorization:
"Basic " +
new Buffer(
process.env.SAFECAST_USERNAME + ":" + process.env.SAFECAST_PASSWORD
).toString("base64"),
};

const init = async () => {
await server.register([
{
plugin: require('@hapi/inert'),
options: {}
plugin: require("@hapi/inert"),
options: {},
},
{
plugin: require('hapi-pino'),
plugin: require("hapi-pino"),
options: {
prettyPrint: true,
logEvents: ['response', 'onPostStart']
}
}]);
logEvents: ["response", "onPostStart"],
},
},
]);

server.route({
method: 'GET',
path: '/',
method: "GET",
path: "/",
options: {
cors: {
origin: [
'http://localhost:5000',
'https://airnote.live'
]
origin: ["http://localhost:5555", "https://airnote.live"],
},
handler: async (request, h) => {
const device_uid = request.query.device_uid;
const to = request.query.to;
const from = request.query.from;

try {
const response = await axios.post(url, buildBody(device_uid, to, from), {
headers: headers,
});
return h.response(response.data)
.type('application/json')
.code(200);
} catch(err) {
const response = await axios.post(
url,
buildBody(device_uid, to, from),
{
headers: headers,
}
);
return h.response(response.data).type("application/json").code(200);
} catch (err) {
return h.response().code(500);
}
}
}
},
},
});

await server.start();
console.log(`Server running at: ${server.info.uri}`);
};

process.on('unhandledRejection', (err) => {
process.on("unhandledRejection", (err) => {
console.log(err);
process.exit(1);
});

init();
init();

0 comments on commit c83fd88

Please sign in to comment.