Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
304CEM-Coursework-BackEnd/server.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (36 sloc)
862 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
IMPORTED MODULES | |
express : the framework | |
cors : cross-origin resource sharing | |
bodyParser : enabling HTTP POST request | |
*/ | |
'use strict'; | |
const express = require('express'); | |
const cors = require('cors'); | |
const bodyParser = require('body-parser'); | |
/* | |
EXPRESS SETTING | |
server var : making express object | |
bodyParser : parsing json | |
cors : enable all origins | |
*cors : enable complex routes | |
static : allow static files to serve images | |
*/ | |
const server = express(); | |
server.use(bodyParser.json()); | |
server.use(cors()); | |
server.options('*', cors()); | |
server.use(express.static('public')); | |
//main routes for api end point | |
const routes = require('./routes'); | |
routes.allRoutes(server); | |
//port number | |
let port = 8080; | |
//start server | |
server.listen(port, err => { | |
if (err) { | |
console.error(err) | |
} else { | |
console.log(`StuTrade BackEnd Running at PORT: ${port}`); | |
} | |
}); |