Skip to content

Instantly share code, notes, and snippets.

@pepetox
Last active April 1, 2020 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepetox/df321d60c02adf14d2fd63982b9d5f40 to your computer and use it in GitHub Desktop.
Save pepetox/df321d60c02adf14d2fd63982b9d5f40 to your computer and use it in GitHub Desktop.
server.js Front with GAE

How to use

  1. Init the npm repo
  2. Install express
  3. Copy server.js and app.yaml
  4. Copy static files to /www
  5. gcloud app deploy --project project-id
runtime: nodejs10
service: default
{
"name": "myfront",
"version": "1.0.0",
"description": "npm init",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'www')));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'www', 'index.html'));
});
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment