Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 角度+;节点+;Express:使用sendFile方法的意外令牌_Node.js_Angular_Express_Auth0_Sendfile - Fatal编程技术网

Node.js 角度+;节点+;Express:使用sendFile方法的意外令牌

Node.js 角度+;节点+;Express:使用sendFile方法的意外令牌,node.js,angular,express,auth0,sendfile,Node.js,Angular,Express,Auth0,Sendfile,我被困在这里了。我正在编写一个Web应用程序,客户端使用Angular 4,服务器端使用Node/Express/Mongo编写REST API,使用Auth0 API进行身份验证 在服务器端,我提供静态文件和到Angular的所有路由,如下所示: const distDir = __dirname + "/dist/"; app.use(express.static(distDir)); app.get('/*', function(req, res) { res.sendFile(

我被困在这里了。我正在编写一个Web应用程序,客户端使用Angular 4,服务器端使用Node/Express/Mongo编写REST API,使用Auth0 API进行身份验证

在服务器端,我提供静态文件和到Angular的所有路由,如下所示:

const distDir = __dirname + "/dist/";
app.use(express.static(distDir));

app.get('/*', function(req, res) {
    res.sendFile(path.join(__dirname + '/dist/index.html'));
});
如果没有为所有Angular应用程序提供服务的app.get方法,则会出现404错误(例如,无法获取/回调)

问题是sendFile发送一个html文件,不管调用是什么。在我的应用程序中,第一个调用是js文件,如网络选项卡(auth0.min.js)中所示。所以我得到了这个错误:

ERROR SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at e.CPp0.t.json (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
    at e.project (main.0e8acae237e497f792ab.bundle.js:1)
    at e._next (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
    at e.T14+.e.next (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
    at XMLHttpRequest.s (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
    at e.invokeTask (polyfills.043084ca495430fc14f3.bundle.js:1)
    at Object.onInvokeTask (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
    at e.invokeTask (polyfills.043084ca495430fc14f3.bundle.js:1)
    at r.runTask (polyfills.043084ca495430fc14f3.bundle.js:1)
错误SyntaxError:JSON中位于位置0的意外标记<
在JSON.parse()处
在e.CPp0.t.json(vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.project(main.0e8acae237e497f792ab.bundle.js:1)
下一步在e._(vendor.b69a8a4fa217eba4fba0.bundle.js:1)
在e.T14+e.next(vendor.b69a8a4fa217eba4fba0.bundle.js:1)
在XMLHttpRequest.s(vendor.b69a8a4fa217eba4fba0.bundle.js:1)
在e.invokeTask(polyfills.043084ca495430fc14f3.bundle.js:1)
位于Object.onInvokeTask(vendor.b69a8a4fa217eba4fba0.bundle.js:1)
在e.invokeTask(polyfills.043084ca495430fc14f3.bundle.js:1)
在r.runTask(polyfills.043084ca495430fc14f3.bundle.js:1)
我猜身份验证需要解析一些json文件,但是sendFile方法发送HTML。我无法解决这个问题。有人能帮我吗