Answer the question
In order to leave comments, you need to log in
How to process index.html?
In general, I stopped at the beginning of the beginning.
I have a project structure
app
--index.html
bower_components
server.js
, i.e. server.js is at the root, the index.php file is at the root of the app folder. var express = require('express');
var app = express();
var morgan = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
app.set('views', 'app');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(bodyParser.urlencoded({'extended': 'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({type: 'application/vnd.api+json'})); // parse application/vnd.api+json as json
app.use(methodOverride());
// listen (start app with node server.js) ======================================
app.listen(8080);
console.log("App listening on port 8080");
app.get('/*', function (req, res) {
res.render('index.html'); // load the single view file (angular will handle the page changes on the front-end)
});
<!DOCTYPE html>
<!--[if lt IE 7]> <html lang="en" ng-app="app" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html lang="en" ng-app="app" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html lang="en" ng-app="app" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="app" class="no-js"> <!--<![endif]-->
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- bower:css -->
<link rel="stylesheet" href="../bower_components/angular-material/angular-material.css" />
<!-- endbower -->
<link href="app/core/client/css/core.css" rel="stylesheet" type="text/css">
<link href="app/ehr/client/css/ehr.css" rel="stylesheet" type="text/css">
</head>
<body>
<div ng-include="'core/client/views/header.view.client.html'"></div>
<div ui-view class="main-inner"></div>
<!-- bower:js -->
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-loader/angular-loader.js"></script>
...
</body>
Uncaught SyntaxError: Unexpected token <
Answer the question
In order to leave comments, you need to log in
Specify the path to static resources through express.static, for example, the project root
app.set('views', 'app');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(express.static(__dirname + '/')); <-- this
<link href="/app/core/client/css/core.css" rel="stylesheet" type="text/css">
<link href="/app/ehr/client/css/ehr.css" rel="stylesheet" type="text/css">
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-loader/angular-loader.js"></script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question