我如何使用Restify运行angular7

时间:2019-07-10 18:13:54

标签: node.js angular7

我正在使用Angular7和restify8.3.2。开发一个应用程序。 我需要在服务器上部署我的应用程序。下面是我的server.js(重新验证)的代码

const restify = require ('restify'),
  server = restify.createServer(),
  passport = require ('passport'),
  corsMiddleware = require('restify-cors-middleware'),
  cors = corsMiddleware({
    preflightMaxAge: 5, //Optional
    origins: ['*'],
    allowHeaders: ['Authorization'],
    exposeHeaders: ['*']
  }),
  path = require('path');

require('dotenv').config();

const port = process.env.PORT;

server.pre(cors.preflight)
server.use(cors.actual)

// use restify plugin for post request
server.use (restify.plugins.bodyParser());
server.use(restify.plugins.queryParser());

// validate passport authentication
require('./passport')(passport);
server.use(passport.initialize());

// angular7 routes and build
server.get('/.*/', restify.plugins.serveStatic({
  directory: path.join(__dirname, 'dist', 'frontend'),
  default: 'index.html',
  maxAge:1
}));

// Restify routes
require ('./app/routes') (server, passport);


server.listen (port, () => {
  console.info (`server is running on ${server.url}`);
});

它正在工作,并且具有angular7根(http://localhost:3000/),但是当我尝试运行子路线时,它给出了类似的错误

{"code":"ResourceNotFound","message":"/login does not exist"}

如何运行angular7路线?

0 个答案:

没有答案