Browse Source

Made static file server in node serve the home page.

master
jrtechs 5 years ago
parent
commit
73e7e23dde
3 changed files with 65 additions and 56 deletions
  1. +6
    -0
      .idea/vcs.xml
  2. +0
    -45
      index.html
  3. +59
    -11
      server.js

+ 6
- 0
.idea/vcs.xml View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 0
- 45
index.html View File

@ -17,54 +17,9 @@
<script type='text/javascript' src='https://darksky.net/widget/default/43.1573,-77.6152/us12/en.js?width=100%&height=350&title=Rochester NY&textColor=333333&bgColor=transparent&transparency=true&skyColor=undefined&fontFamily=Default&customFont=&units=us&htColor=333333&ltColor=C7C7C7&displaySum=yes&displayHeader=yes'></script>
</div>
<div class="col col-md-6 col-12">
<!-- start sw-rss-feed code -->
<script type="text/javascript">
rssfeed_url = new Array();
rssfeed_url[0]="https://news.google.com/news/rss";
rssfeed_frame_width="100%";
rssfeed_frame_height="260";
rssfeed_scroll="off";
rssfeed_scroll_step="20";
rssfeed_scroll_bar="on";
rssfeed_target="_blank";
rssfeed_font_size="12";
rssfeed_font_face="";
rssfeed_border="on";
rssfeed_css_url="";
rssfeed_title="on";
rssfeed_title_name="";
rssfeed_title_bgcolor="#3366ff";
rssfeed_title_color="#fff";
rssfeed_title_bgimage="";
rssfeed_footer="off";
rssfeed_footer_name="rss feed";
rssfeed_footer_bgcolor="#fff";
rssfeed_footer_color="#333";
rssfeed_footer_bgimage="";
rssfeed_item_title_length="50";
rssfeed_item_title_color="#666";
rssfeed_item_bgcolor="#fff";
rssfeed_item_bgimage="";
rssfeed_item_border_bottom="on";
rssfeed_item_source_icon="off";
rssfeed_item_date="off";
rssfeed_item_description="on";
rssfeed_item_description_length="120";
rssfeed_item_description_color="#666";
rssfeed_item_description_link_color="#333";
rssfeed_item_description_tag="off";
rssfeed_no_items="0";
rssfeed_cache = "2220318b43254a73f6fcdb3732f0e710";
</script>
<script type="text/javascript" src="//feed.surfing-waves.com/js/rss-feed.js"></script>
<!-- The link below helps keep this service FREE, and helps other people find the SW widget. Please be cool and keep it! Thanks. -->
<div style="color:#ccc;font-size:10px; text-align:right; width:100%;">powered by <a href="https://surfing-waves.com" rel="noopener" target="_blank" style="color:#ccc;">Surfing Waves</a></div>
<!-- end sw-rss-feed code -->
</div>
</div>
</body>
</html>

+ 59
- 11
server.js View File

@ -73,23 +73,71 @@ app.get('/error', (request, result) =>
});
app.get('/', (request, result) =>
const queryAPI = function(result, path)
{
if(accessTokenTemp == null)
return new Promise((resolve, reject)=>
{
result.redirect('/auth/fitbit');
}
if(accessTokenTemp == null)
{
result.redirect('/auth/fitbit');
resolve(false);
}
unirest.get(path)
.headers({'Accept': 'application/json', 'Content-Type': 'application/json', Authorization: "Bearer " + accessTokenTemp})
.end(function (response)
{
if(response.hasOwnProperty("success") && response.success == false)
{
result.redirect('/auth/fitbit');
resolve(false);
}
resolve(response.body);
});
});
};
app.get('/steps', (request, result)=>
{
queryAPI(result, 'https://api.fitbit.com/1/user/-/activities/tracker/steps/date/today/1m.json').then((data)=>
{
if(data != false)
{
result.writeHead(200, {'Content-Type': 'text/html'});
result.write(JSON.stringify(data));
result.end();
}
else
{
console.log("Validating with API");
}
});
});
unirest.get('https://api.fitbit.com/1/user/-/activities/steps/date/today/1m.json')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json', Authorization: "Bearer " + accessTokenTemp})
.end(function (response)
app.get('/activities', (request, result)=>
{
queryAPI(result, 'https://api.fitbit.com/1/user/-/activities/date/1M.json').then((data)=>
{
if(data != false)
{
// result.write(response.body);
result.writeHead(200, {'Content-Type': 'text/html'});
result.write(JSON.stringify(data));
result.end();
console.log(response.body);
});
}
else
{
console.log("Validating with API");
}
});
});
app.get('/', (request, result) =>
{
result.write(utils.getFile("index.html"));
result.end();
});
app.listen(PORT, () =>
app.listen(config.port, () =>
console.log(`App listening on port ${config.port}!`)
);

Loading…
Cancel
Save