Giter Site home page Giter Site logo

graysonliu / spotify-charts-generator-static Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 8.83 MB

A purely static web app that helps you create playlists in Spotify based on charts from https://spotifycharts.com.

Home Page: https://graysonliu.github.io/spotify-charts-generator-static

JavaScript 83.89% HTML 4.94% SCSS 11.18%

spotify-charts-generator-static's Introduction

https://graysonliu.github.io/spotify-charts-generator-static/

spotify-charts-generator-static

This is a Spotify web app purely hosted on Github Pages. It can help you create playlists based on daily charts from Spotify Charts.

Since Github Pages is purely static and this web app has no back end, necessary information like client secret can only be obtained from the web app itself at runtime. Therefore, we injected those information into the web page at build time using HtmlWebpackPlugin:

plugins: [
    ...
    new HtmlWebpackPlugin({
        template: "./src/template.ejs",
        ...
        // inject environment variables into pages at build time
        window: {
            env: {
                client_id: process.env.CLIENT_ID,
                client_secret: process.env.CLIENT_SECRET,
                redirect_uri: process.env.REDIRECT_URL,
                scopes: process.env.SCOPES,
                charts: charts
            }
        }
        ...
    }),
    ...
]

Also, because of denied access in CORS policy of Spotify Charts, we cannot get charts data at runtime, meaning that charts data should also be injected into the page at build time. To make sure that we have the latest charts data, this app will be rebuilt every 6 hours as scheduled in Github Actions. Overall, we provide four environment variables at build time that will be injected into the web page, as well as the charts data that is fetched by pre_build.js.

The injection is achieved by following snippet in template.ejs:

<!-- inject environment variables into pages at build time -->
<script type="text/javascript">
    <% for (key in htmlWebpackPlugin.options.window) { %>
    window['<%= key %>'] = <%= JSON.stringify(htmlWebpackPlugin.options.window[key]) %>;
    <% } %>
</script>

Warning

The client secret of a Spotify Web App is not supposed to be exposed, but it is exposed in this app because the only way to get the client secret in this purely static app at runtime is to inject it into the web page. In practice, we should have a back end that handles token exchanges.

spotify-charts-generator-static's People

Contributors

graysonliu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.