2017-02-04 4 views
2

Я пробовал все там. У меня очень простое приложение ng2. Это структура файла:Экспресс с угловой 2 cli

mean 
    |- client (where the ng2 app lives) 
    | |- dist 
    | |- (all ng2 app folders)... 
    |- node_modules 
    |- routes 
    | |- index.js 
    |- views 
    |- package.json 
    |- server.js 

index.js:

var express = require('express'); 
var router = express.Router(); 

router.get('/', (req, res, next) => { 
    res.render('../client/dist/index.html') 
}) 

module.exports = router; 

Когда я запускать server.js и перемещаться в локальном хосте: 3000, сценарии просто не груз:

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:3000/inline.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:3000/vendor.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:3000/main.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:3000/styles.bundle.css Failed to load resource: the server responded with a status of 404 (Not Found) 

Но средняя> клиентская> папка dist имеет все js-файлы. Есть идеи?

ответ

4

вам нужно обслуживать статическую папку, ../client/dist

app.use(express.static(path.join(__dirname, 'client/dist'))) 

app.route('/*', (req, res, next) { 
    // do something 
}); 
+1

Genious! Это решило проблему. Спасибо –

+0

@GastonK вы должны принять этот ответ, так как он решил проблему. –

+0

Сделано @LajosArpad! –

Смежные вопросы