在调试模式下,我无法提供静态文件服务。我正在使用Passport身份验证。Index.html是登录页面,其中包含表单(POST到/login)。在调试模式下,成功验证后服务器重定向到/home,但我无法获取我的css和javascript文件。
这些文件位于/public目录中。
/public
/css
/javascripts
/images
index.html
home.html
/routes
在 app.js 文件中:
app.use(express.static(path.join(__dirname, 'public')));
在 routes/index.js 中
/* GET Home Page */
router.get('/home', isAuthenticated, function(req, res){
var root = join(__dirname, '/..');
root = join(root, '/public/');
res.sendFile('home.html', { root: root});
});
/* Handle Login POST */
router.post('/login', passport.authenticate('login', {
successRedirect: '/home',
failureRedirect: '/',
failureFlash : true
}));
我正在使用VS Code。这是我的launch.json文件。
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/bin/www",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command.PickProcess}",
"port": 5858,
"sourceMaps": false,
"outDir": null
}
]
}
- miuosh