Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no need to use express.static() for static-files sample #889

Closed
mrdulin opened this issue Nov 13, 2018 · 3 comments
Closed

There is no need to use express.static() for static-files sample #889

mrdulin opened this issue Nov 13, 2018 · 3 comments

Comments

@mrdulin
Copy link

mrdulin commented Nov 13, 2018

Here is my sample:

server.js

const express = require('express');
const path = require('path');
const package = require('./package.json');

function createServer() {
  const app = express();
  app.set('views', path.resolve(__dirname, './views'));
  app.set('view engine', 'ejs');

  // app.use('/static', express.static(path.resolve(__dirname, 'public')));

  app.get('/', (req, res) => {
    res.render('index');
  });

  app.get('/version', (req, res) => {
    res.send(`version: ${package.version}`);
  });

  const PORT = process.env.PORT || 8080;
  return app.listen(PORT, () => {
    console.log(`Server listening on port ${PORT}...`);
  });
}

createServer();

./views/index.ejs

<!DOCTYPE html>
<html lang="en">
  <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" />
    <link rel="stylesheet" href="static/index.css" />
    <title>GAE Static File</title>
  </head>
  <body>
    <h1 class="red">GAE Static File</h1>
  </body>
</html>

app.yaml:

service: static-files
runtime: nodejs8
handlers:
  - url: /static
    static_dir: public

works fine.

image

@fhinkel
Copy link
Contributor

fhinkel commented Nov 13, 2018

@mrdulin Thanks for opening the issue. Is your sample replacing an existing sample?

@mrdulin
Copy link
Author

mrdulin commented Nov 14, 2018

@fhinkel Sorry. What do you mean replacing an existing sample?

Here is my sample:

https://github.com/mrdulin/nodejs-gcp/tree/master/src/app-engine/standard/static-files

@fhinkel
Copy link
Contributor

fhinkel commented Feb 28, 2019

@mrdulin Thanks! We want to show in the sample that both /public and /static serve static files via different configurations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants