Как получить целевую страницу с помощью пользовательского интерфейса angularjs и node.js - PullRequest
0 голосов
/ 24 февраля 2019

Я создаю приложение, используя

  • Anglarjs
  • UI router
  • node.js

и мне нужно получитьпервая / целевая страница при запуске URL.Вот код ниже.

Узел / app.js:

require('./config/config');
require('./models/db');
require('./config/passportConfig');

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');

const passport = require('passport');

const rtsIndex = require('./routes/index.router');

var app = express();
//var corsOptions = {"origin": "http://localhost:4202", "methods": "GET,PUT,DELETE,POST", "preflightContinue": false, "optionsSuccessStatus": "204"};
//app.use(cors(corsOptions));

// middleware app.use( bodyParser.urlencoded({ extended: true }) );
app.use(bodyParser.json());
app.use(cors());
app.use(passport.initialize());
app.use('/api', rtsIndex);
app.use(express.static(__dirname + '/public'));     // set the static files location /public/img will be /img for users
app.use(morgan('dev'));                     // log every request to the console
app.use(bodyParser.urlencoded({ extended: false,limit: '5mb' }))    // parse application/x-www-form-urlencoded
app.use(methodOverride());                  // simulate DELETE and PUT
app.get('/',function(req,res){
    res.sendfile('views/login.html');
});

// error handler
app.use((err, req, res, next) => {
    if (err.name === 'ValidationError') {
        var valErrors = [];
        Object.keys(err.errors).forEach(key => valErrors.push(err.errors[key].message));
        res.status(422).send(valErrors)
    }
    else{
        console.log(err);
    }
});

// start server
app.listen(process.env.PORT, () => console.log(`Server started at port : ${process.env.PORT}`));

angularjs / index.html:

<!DOCTYPE html>
<html lang="en" ng-app="lendingkart">
<head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Welcome to Lendingkart</title>
        <link rel="icon" href="dist/images/favicon.png" />       
        <!--Plugin CSS-->
        <link href="dist/css/plugins.min.css" rel="stylesheet">
        <!--main Css-->
        <link href="dist/css/main.min.css" rel="stylesheet">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.jquery.min.js"></script>
        <script src="dist/js/angularjslatest.js" type="text/javascript"></script>
        <script src="dist/js/angularuirouterlatest.js" type="text/javascript"></script>
        <script src="dist/js/route.js" type="text/javascript"></script>
        <script src="dist/js/angularcaps.js" type="text/javascript"></script>
        <script src="dist/js/angular-messages.js" type="text/javascript"></script>
        <script src="dist/js/angularuibootstrap.js" type="text/javascript"></script>
        <script src="dist/js/ng-file-upload-shim.min.js"></script>
        <script src="dist/js/ng-file-upload.min.js"></script>
        <script src="dist/js/dirPagination.js"></script>
        <script src="dist/js/angular-chosen.min.js"></script>

    </head>
    <body>
    <div  ui-view>

    </div>
        <!-- jQuery -->
        <script src="dist/js/plugins.min.js"></script>
        <script src="dist/js/common.js"></script>
        <script src="dist/js/jquery.mousewheel.min.js" charset="utf-8"></script>
        <script src="dist/js/raphael.min.js" charset="utf-8"></script>
        <script src="dist/js/jquery.mapael.js" charset="utf-8"></script>
        <script src="dist/js/india.js" charset="utf-8"></script>
</body>
</html>

Здесь я использую Angular UI-router для целей маршрутизации.

angularjs / dist / route.js:

var Admin=angular.module('lendingkart',['ui.router', '720kb.datepicker','ngMessages','ngCapsLock','ui.bootstrap','ngFileUpload','angularUtils.directives.dirPagination','angular.chosen']);
Admin.run(function($rootScope, $state) {
    $rootScope.$state = $state;
});
Admin.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
    $urlRouterProvider.otherwise('/');
    $stateProvider
    .state('/',{
        url: '/',
        templateUrl: 'views/login.html',
        controller: 'loginController'
    })
})

Здесь мне нужен один сервер узлазапустится, и пользователь нажмет на ссылку e.g.-localhost:3000, страница входа должна быть показана пользователю.

...