EJS and serving static files

261
April 01, 2018, at 11:53 PM

I am able to serve my css and js on my 1st layer of routes "/", however when I add another layer "admin/login" node/express can't find my public folder. I am pretty new to javascript frameworks and I couldn't find anything online.

Index.js

//Importing Routes into the Project
const websiteRoutes = require('./api/routes/sites');
const loginRoutes = require('./api/routes/login');
//View Engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/api/views'));
//Set Static Path
app.use(express.static(path.join(__dirname, '/public')));

//Handles Route requests from browsers
app.use('/', websiteRoutes);
app.use('/admin/login', loginRoutes);

login.js (loginRoutes)

const express = require('express');
const router = express.Router();
const mongoose = require("mongoose")
router.get('/', function (req, res) {
    var title = 'Admin Login';
    res.render('login/login', {title:title});
})
router.post('/', function (req, res) {
    var title = 'Admin Login';
    res.render('login', {title:title});
})
module.exports = router;

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title> <%- title %> </title>
    <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> -->
    <link rel="stylesheet" href="styles/styles.css">
    <link href="open-iconic-master/font/css/open-iconic-bootstrap.css" rel="stylesheet">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
    <link rel="manifest" href="/site.webmanifest">
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">
</head>
<body id="myPage">

Result

GET /admin/login/ 304 2.257 ms - -
GET /admin/login/styles/styles.css 404 0.388 ms - 33
GET /admin/login/open-iconic-master/font/css/open-iconic-bootstrap.css 404 0.312 ms - 33
GET /admin/login/js/scripts.js 404 0.204 ms - 33
GET /admin/login/images/brand.svg 404 0.264 ms - 33
GET /admin/login/js/scripts.js 404 0.188 ms - 33
READ ALSO
Is there any way to know if a file is being opened by the user?

Is there any way to know if a file is being opened by the user?

My question is simpleI am creating an electron app using Node JS to watch a particular directory

160
Passport JWT strategy not being triggered

Passport JWT strategy not being triggered

I have the following code, but my passport-jwt strategy is not being triggered:

234
Webpack&#39;s removes classnames when minifying/uglifying ES6 code with inheritance

Webpack's removes classnames when minifying/uglifying ES6 code with inheritance

Webpack's removes classnames when minifying/uglifying ES6 code with inheritance:

175