Initial commit from Gomix.
This commit is contained in:
parent
6b5da76e94
commit
a3d70def2a
7 changed files with 186 additions and 2 deletions
59
server.js
Normal file
59
server.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/******************************************************
|
||||
* PLEASE DO NOT EDIT THIS FILE
|
||||
* the verification process may break
|
||||
* ***************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
if (!process.env.DISABLE_XORIGIN) {
|
||||
app.use(function(req, res, next) {
|
||||
var allowedOrigins = ['https://narrow-plane.gomix.me', 'https://www.freecodecamp.com'];
|
||||
var origin = req.headers.origin || '*';
|
||||
if(!process.env.XORIG_RESTRICT || allowedOrigins.indexOf(origin) > -1){
|
||||
console.log(origin);
|
||||
res.setHeader('Access-Control-Allow-Origin', origin);
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
}
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
app.use('/public', express.static(process.cwd() + '/public'));
|
||||
|
||||
app.route('/_api/package.json')
|
||||
.get(function(req, res, next) {
|
||||
console.log('requested');
|
||||
fs.readFile(__dirname + '/package.json', function(err, data) {
|
||||
if(err) return next(err);
|
||||
res.type('txt').send(data.toString());
|
||||
});
|
||||
});
|
||||
|
||||
app.route('/')
|
||||
.get(function(req, res) {
|
||||
res.sendFile(process.cwd() + '/views/index.html');
|
||||
})
|
||||
|
||||
// Respond not found to all the wrong routes
|
||||
app.use(function(req, res, next){
|
||||
res.status(404);
|
||||
res.type('txt').send('Not found');
|
||||
});
|
||||
|
||||
// Error Middleware
|
||||
app.use(function(err, req, res, next) {
|
||||
if(err) {
|
||||
res.status(err.status || 500)
|
||||
.type('txt')
|
||||
.send(err.message || 'SERVER ERROR');
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(process.env.PORT, function () {
|
||||
console.log('Node.js listening ...');
|
||||
});
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue