简体   繁体   English

从弹性beantalk提供静态文件不起作用

[英]Serving static files from elastic beanstalk not working

I got an angular app that is working perfectly fine from localhost, but on beanstalk it's not serving all my files. 我有一个可以从本地主机正常工作的有角度的应用程序,但是在beantalk上,它不能提供我的所有文件。 Only my index.html and styles.css is found and served, both are in one folder called public in my root. 只能找到并提供我的index.html和styles.css,它们都位于我根目录下的一个名为public的文件夹中。 my build file is in the path /build/build.js and it won't serve it but on local host it will. 我的构建文件位于/build/build.js路径中,它不会提供服务,但会在本地主机上提供。

I'm currently just serving files from my server and not using the staticfiles.config since that is completely not working. 我目前仅从服务器提供文件,而不使用staticfiles.config,因为这完全无法正常工作。

folder structure: 文件夹结构:

root:  
/public : index.html ,styles.css
/src: modularized angular and htmls for routes . 
/build: build.js

 const express = require('express'); const path = require('path'); const fs = require('fs'); const bodyParser = require('body-parser'); const emailController = require('./controllers/emailController'); const app = express(); const port = process.env.PORT || 3000; app.use(bodyParser.json()); app.use(express.static(path.resolve(__dirname, '../public'))); app.use(express.static(path.resolve(__dirname, '../'))); app.post('/email', emailController); app.listen(port, () => { console.log(`Server is listening on mfing ${port}`); }); 
 <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta name="description" content="Hydration Packs and Cooler Bags for Hiking, Outdoors, Work, Festivals, Biking and More"> <link rel="stylesheet" type="text/css" href="./styles.css"> <script src="/node_modules/angular/angular.js"></script> <script src="/node_modules/angular-route/angular-route.js"></script> <script src="/build/build.js"></script> <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet"> <title>Hydration Packs and Cooler bags | Absolute Zero</title> </head> 

Here is my server and head of my index.html. 这是我的服务器,也是index.html的头。 anyone know what's wrong? 有人知道怎么了吗? Thanks. 谢谢。

Replace the script searches with this. 以此替换脚本搜索。 you need to use ./ . 您需要使用./

  <script src="./node_modules/angular/angular.js"></script>
  <script src="./node_modules/angular-route/angular-route.js"></script>
  <script src="./build/build.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM