mirror of
				https://codeberg.org/buzzcode2007/FCC-Project-URLShortener.git
				synced 2025-05-21 03:06:34 +00:00 
			
		
		
		
	
						commit
						b21402a37b
					
				
					 1 changed files with 12 additions and 14 deletions
				
			
		
							
								
								
									
										24
									
								
								server.js
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								server.js
									
										
									
									
									
								
							|  | @ -1,15 +1,13 @@ | ||||||
| 'use strict'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
| var express = require('express'); | const express = require('express'), | ||||||
| var mongo = require('mongodb'); |       mongo = require('mongodb'), | ||||||
| var mongoose = require('mongoose'); |       mongoose = require('mongoose'), | ||||||
| 
 |       cors = require('cors'), | ||||||
| var cors = require('cors'); |       app = express(); | ||||||
| 
 |  | ||||||
| var app = express(); |  | ||||||
| 
 | 
 | ||||||
| // Basic Configuration 
 | // Basic Configuration 
 | ||||||
| var port = process.env.PORT || 3000; | const port = process.env.PORT || 3000; | ||||||
| 
 | 
 | ||||||
| /** this project needs a db !! **/  | /** this project needs a db !! **/  | ||||||
| // mongoose.connect(process.env.DB_URI);
 | // mongoose.connect(process.env.DB_URI);
 | ||||||
|  | @ -19,19 +17,19 @@ app.use(cors()); | ||||||
| /** this project needs to parse POST bodies **/ | /** this project needs to parse POST bodies **/ | ||||||
| // you should mount the body-parser here
 | // you should mount the body-parser here
 | ||||||
| 
 | 
 | ||||||
| app.use('/public', express.static(process.cwd() + '/public')); | app.use('/public', express.static(`${process.cwd()}/public`)); | ||||||
| 
 | 
 | ||||||
| app.get('/', function(req, res){ | app.get('/', (req, res) => { | ||||||
|   res.sendFile(process.cwd() + '/views/index.html'); |   res.sendFile(`${process.cwd()}/views/index.html`); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|    |    | ||||||
| // your first API endpoint... 
 | // your first API endpoint... 
 | ||||||
| app.get("/api/hello", function (req, res) { | app.get("/api/hello", (req, res) => { | ||||||
|   res.json({greeting: 'hello API'}); |   res.json({greeting: 'hello API'}); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| app.listen(port, function () { | app.listen(port, () => { | ||||||
|   console.log('Node.js listening ...'); |   console.log('Node.js listening ...'); | ||||||
| }); | }); | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue