Advertisement
Guest User

old

a guest
Mar 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright 2018, Google LLC.
  2. // Licensed under the Apache License, Version 2.0 (the "License");
  3. // you may not use this file except in compliance with the License.
  4. // You may obtain a copy of the License at
  5. //
  6. //    http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13.  
  14. 'use strict';
  15.  
  16. const express = require('express');
  17. const app = express();
  18.  
  19. const path = require('path');
  20.  
  21. const bodyParser = require('body-parser');
  22.  
  23. // [START hello_world]
  24. // Say hello!
  25. app.get('/', (req, res) => {
  26.   res.status(200).sendFile(path.join(__dirname + '/client/index.html'));
  27.   if (req.method == 'POST') {
  28.     console.log("Posted");
  29.   }
  30. });
  31. app.use('/', express.static('client'));
  32.  
  33. app.use('/REST', bodyParser.json()); // support json encoded bodies
  34. app.post('/REST/test', function(req, res) {
  35.   var hey = req.body.hey;
  36.   console.log(hey);
  37.   res.send(hey);
  38. });
  39. // [END hello_world]
  40.  
  41. if (module === require.main) {
  42.   // [START server]
  43.   // Start the server
  44.   const server = app.listen(process.env.PORT || 8080, () => {
  45.     const port = server.address().port;
  46.     console.log(`App listening on port ${port}`);
  47.   });
  48.   // [END server]
  49. }
  50.  
  51. module.exports = app;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement