0

When I put into addressbar the css, images work but my javascript files not work.

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.)

My 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:



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. I tried :


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

- url: /build/.*
  static_dir: static/build
  • Hi, you might take a look into this [previous question](https://stackoverflow.com/questions/5609000/serve-static-file-using-app-engine). It talks about the handlers and there is an example with javascript content. ` url: /(.*\.js) mime_type: text/javascript static_files: static/\1 upload: static/(.*\.js)` – Joss Baron Nov 01 '19 at 21:35
  • The problem using static_files or static_dir is the same, only files non javascrupt are accept. I tried - url: /build/(.*) static_files: static/build/\1 upload: static/build/(.*) - url: /build/.* static_dir: static/build – Edson Vicente Carli Junior Nov 03 '19 at 16:34
  • Using url: /build/(.+) not work too – Edson Vicente Carli Junior Nov 03 '19 at 16:43
  • Have you tried without /build? just 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: - 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. If I try with /static/example.js this does not work. – Joss Baron Nov 05 '19 at 23:44

1 Answers1

0

Have you tried the request without /build? just 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:

- 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. If I try with /static/example.js this does not work.

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

I have followed this github

Joss Baron
  • 1,441
  • 10
  • 13