alisnic / nyny Goto Github PK
View Code? Open in Web Editor NEWa (ridiculously) small and powerful web framework.
Home Page: http://alisnic.github.io/nyny/
License: MIT License
a (ridiculously) small and powerful web framework.
Home Page: http://alisnic.github.io/nyny/
License: MIT License
When namespacing some requests, if you visit just the namespace url
/api/v1
for example, instead of
/api/v1/all
then the program will reach the "get '/' do" which is outside of the namespace. Is this the intended behavior?
A code sample is below.
namespace '/api' do
namespace '/v1' do
get '/all' do
content_type :json
{ a_key: "some_data", version: "2.0.3" }.to_json
end
end
end
get '/' do
use Rack::Static, :urls => [""], :root => 'public', :index => 'index.html'
content_type :html
render './public/index.html'
end
Hi,
I want to use nyny as a RESTFul JSON API ... But it raise me an error when I try to run an ajax call from an another domain.
$.get("http://localhost:9292", function(data) { console.log(data) });
provide me an Access-Control-Allow-Origin
error !
How can I accept any request ?
Thanks
If I want to catch every request that doesn't have a route?
NYNY::App instances share their middlewares unexpectedly.
Example:
require 'nyny'
require 'rack'
Rack::Server.start app: Rack::Builder.app {
use Class.new(NYNY::App) {
use Rack::CommonLogger
get '/' do
'This is WebApp.'
end
}
use Class.new(NYNY::App) {
use Rack::CommonLogger # shouldn't reach here.
get '/' do
'This is APIApp.'
end
}
run proc {}
}
The HTTP responses are correct, but the application emits every same access logs twice, like this:
$ curl localhost:8080
This is WebApp.
127.0.0.1 - - [25/Feb/2014 14:05:01] "GET / HTTP/1.1" 200 15 0.0005
127.0.0.1 - - [25/Feb/2014 14:05:01] "GET / HTTP/1.1" 200 15 0.0010
require 'nyny'
class Ping < NYNY::App
get '/' do #this will be accessbile at '/ping'
'pong'
end
end
class App < NYNY::App
get '/' do
'Hello'
end
# You can pass a Rack app to the namespace
namespace '/ping', Ping
# Or you can pass a block, which will create the app for you
namespace '/nested' do
get '/' do # this will be accessible at '/nested'
'Hello from namespace!'
end
end
end
visit http://localhost:9292/nested/ is ok
visit http://localhost:9292/ping throw ArgumentError
it seems that namespace only works fine with block but not for class
Failing spec
it 'allows to use middlewares inside namespace' do
kls = Class.new(NYNY::Base) do
get '/' do
'foo'
end
end
app = mock_app do
namespace '/foo' do
use kls
end
end
app.get('/foo')
end
Hi do a simple test
get '/' do
{ data: Vehicle.count, test: session[:test] }.to_json
end
get '/s' do
session[:test] = Time.now.to_s
end
When I call '/s' then '/' my session[:test] object looks empty !? How to make it persistent ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.