Integrating Express’ static middleware and securing the admin interface
Before exposing our application to the general public, we will need to secure the admin dashboard routes, along with exposing the static assets for frontend development. First, we will want to create a new directory with an empty file located at public/index.html
. After that, we can start making modifications to the index.js
file (within the project’s root directory). At the top, we will need Node.js’ path module:
const path = require("path");
Just below the app.use('/graphql', server)
block, we will want to tell Express to serve static assets that are found within the public directory:
app.use(express.static(path.join(__dirname, "public")));
Express will try to find a matching file with the associated route in the public directory before cascading down to our API routes (for example, /airplanes
or /flights
). The reason why we use path.join
here is...