I wrote this as a way to deliver static portion of the app. I'm wondering if there is a better way to write this, as I am new to Express.
The goal is to let a single-page app to handle routing as needed. There is an API layer of this app that is defined under the /api/ route namespace.
I wanted to note that all assets are served from /app folder and are not public. I can adjust that, but as of now, that's the folder structure. /app is a compilation destination. root folder contains server.js where the below code resides and contains app/ and src/ folders, as well as server/ folder that contains API related stuff.
var express = require('express');
var http = require('http');
var path = require('path');
var app = express();
require('./express/api')(app);
app.get("/css/*",function(req,res){
res.sendfile('app'+req.path);
});
app.get("/js/*",function(req,res){
res.sendfile('app'+req.path);
});
app.get("/img/*",function(req,res){
res.sendfile('app'+req.path);
});
app.get("/pages/*",function(req,res){
res.sendfile('app'+req.path);
});
app.get('*',function(req,res){
res.sendfile('app/index.html');
});
app.listen(3000);
console.log('Listening on port 3000');