简体   繁体   English

Google App Engile,Node JS,无法为 javascript static 文件提供服务

[英]Google App Engile , Node JS, not work serving javascript static files

When I put into addressbar the css, images work but my javascript files not work.当我将 css 放入地址栏中时,图像可以工作,但我的 javascript 文件不起作用。

Eg:例如:

https://(...).appspot.com/build/teste.css (work) https://(...).appspot.com/build/teste.js (404 error - The requested URL /build/mycomponent.js was not found on this server.) https://(...).appspot.com/build/teste.css (work) https://(...).appspot.com/build/teste.js (404 error - The requested URL /build在此服务器上找不到 /mycomponent.js。)

My app.yaml:我的 app.yaml:


runtime: nodejs10


handlers:
- url: /images
  static_dir: static/images
  expiration: '10s'

- url: /css
  static_dir: static/css
  expiration: '10s'

- url: /build
  static_dir: static/build
  expiration: '10s'

- url: /assets
  static_dir: static/assets
  expiration: '10s'

- url: /static
  static_dir: static/.*
  expiration: '10s'

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto

My structury folder is:我的结构文件夹是:

/static
   /css 
      / *.css(work)
   /images 
      / *.png|jpg (work)
   /assets
      / *.js (not work - 404 in log view)
   /build
      / test.css (work)
      / test.js (not work - 404 in log view) 

My index.ts file is:我的 index.ts 文件是:



import * as express from "express";
import * as fs from "fs";
import * as ejs from "ejs";


const VERSION : string = "1.0.6"; 
const PORT = Number(process.env.PORT) || 8080;
const app = express();



app.use(express.static('static'));
app.set("view engine", "html");
app.engine("html", ejs.renderFile);
app.set("views", __dirname + "/views");


app.use(function(req,res){
    res.render("index");
});



app.listen(PORT, () => {
    console.log(`Server version ${VERSION}`);
    console.log(`App listening on port ${PORT}`);
});

PS: satic_files have the same problems. PS:satic_files 也有同样的问题。 I tried:我试过了:


- url: /build/(.+)
  static_files: static/build/\1
  upload: static/build/(.*)

- url: /build/.*
  static_dir: static/build

Have you tried the request without /build?您是否尝试过没有 /build 的请求? just https://(...).appspot.com/teste.js只是https://(...).appspot.com/teste.js

I have performed an example, I have the following structure:我已经执行了一个示例,我具有以下结构:

-app.yaml -static/ ----example.js

I've set this handlers in the yaml file:我在 yaml 文件中设置了这个处理程序:

- url: /(.*\.js) mime_type: text/javascript static_files: static/\1 upload: static/(.*\.js)

When I access to js resources I do: https://(...).appspot.com/example.js and it works.当我访问 js 资源时,我会这样做: https://(...).appspot.com/example.js并且它可以工作。 If I try with /static/example.js this does not work.如果我尝试使用 /static/example.js 这不起作用。

I have tried with a similar structure as yours:我尝试过与您类似的结构:

-app.yaml -static/ ----assets/ --------example.js

With this handlers:使用此处理程序:

handlers: - url: /static static_dir: static/.* expiration: '10s' - url: /(.*\.js) mime_type: text/javascript static_files: static/assets/\1 upload: static/(.*\.js)

Tried: https://(...).appspot.com/example.js > works Tried: https://(...).appspot.com/assets/example.js > Does not work尝试过: https://(...).appspot.com/example.js > 作品尝试过: https://(...).appspot.com/assets/example.js > 不起作用

I have followed this github我已经关注了这个 github

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

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